.html() garbles div information

Discussion in 'jQuery' started by dethfire, Dec 27, 2010.

  1. #1
    It appears that .html() is somehow messing up reading the contents of a div.

    Here is my php code which loads into the div.

    
    $own_pre_selection .= "<input name='" . mysql_result($result,$i,"did") . "' value='" . mysql_result($result,$i,"did") . "' type='hidden'><span class='addremove' onclick=\"recordchecks('" . mysql_result($result,$i,"dname") . "','" . mysql_result($result,$i,"did") . "')\";><u>Remove</u></span> &nbsp;" . mysql_result($result,$i,"dname") . "<br>";
    
    
    Code (markup):
    Here is what I see as source code after the page renders.

    
    <input name='677' value='677' type='hidden'><span class='addremove' onclick="recordchecks('Heart Neoplasms','677')";><u>Remove</u></span> &nbsp;Heart Neoplasms<br><input name='1298' value='1298' type='hidden'><span class='addremove' onclick="recordchecks('Heart Septal Defects; Atrial','1298')";><u>Remove</u></span> &nbsp;Heart Septal Defects; Atrial<br></div>
    
    
    Code (markup):
    When I test alert() the .html() contents it appears like this. It seems to screw up the quote escape and changes \" to " ;="" after the recordchecks().

    
    <input name="677" value="677" type="hidden"><span class="addremove" onclick="recordchecks('Heart Neoplasms','677')" ;=""><u>Remove</u></span> &nbsp;Heart Neoplasms<br><input name="1298" value="1298" type="hidden"><span class="addremove" onclick="recordchecks('Heart Septal Defects; Atrial','1298')" ;=""><u>Remove</u></span> &nbsp;Heart Septal Defects; Atrial<br>
    
    
    Code (markup):
    So even though the source code looks perfect, if I alert() the div contents with html() it seems to get a bit garbled in the process. Any ideas?
     
    dethfire, Dec 27, 2010 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Your javascript is wrong. The semicolon should be after the js statement not after the quotes:

    
    $own_pre_selection .= "<input name='" . mysql_result($result,$i,"did") . "' value='" . mysql_result($result,$i,"did") . "' type='hidden'><span class='addremove' onclick=\"recordchecks('" . mysql_result($result,$i,"dname") . "','" . mysql_result($result,$i,"did") . "');\"><u>Remove</u></span> &nbsp;" . mysql_result($result,$i,"dname") . "<br>";
    
    Code (markup):
     
    ThePHPMaster, Dec 27, 2010 IP
  3. dethfire

    dethfire Well-Known Member

    Messages:
    230
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    118
    #3
    ahhh makes sense, thanks!!
     
    dethfire, Dec 27, 2010 IP