Skip to content Skip to sidebar Skip to footer

Javascript Number-string Div Onclick Strange Conversion

What I basically do is that I assign the Facebook-ID from a person to a onclick-Event in a DIV. The div is a string itself because I assign it later to a DOM-property via innerHTML

Solution 1:

Maybe you should try

"<div onclick='openFbFriend(\""+ friendsArray[i]['facebookID'] +"\");' class='row'>";

because if you do not have the \" around the argument, then it will be interpreted as an integer or if it contains non-numeric characters then it will result in an error.

The resulting string would be:

<div onclick='openFbFriend("10204840506352732");'class='row'>

But in your version:

<div onclick='openFbFriend(10204840506352732);'class='row'>

Solution 2:

Now I had a quick own guess and fixed it with

    \"


    "<div onclick='openFbFriend(\"" + friendsArray[i]['facebookID'] + "\");' class='row'>"

I assume it is converted to a number without \" but I do not understand why. Maybe sb can explain? Thx

Post a Comment for "Javascript Number-string Div Onclick Strange Conversion"