A table shows data grabbed from a database on my site, when a button is clicked the "enableEditing" function is called using the onclick attribute. Then for one field for each row in the the table, an input textbox appears using the field as the value, and the key as the input name.
Before:
<tr class="data_row"> <td class="property_cell">project ref</td> <td class="myNumber">200407</td> </tr> After:
<tr class="data_row"> <td class="property_cell">project ref</td> <td class="myNumber"> <input name="project ref" value="200407"> </td> </tr> jQuery:
function enableEditing(){ $("#object_data tr").each(function(){ var key = $(this).children(".property_cell").html(); var value = $(this).children(".myNumber").text(); $(this).children(".myNumber").html("<input name='" + key + "' value='" + value + "'>"); }); } This works fine, however some of the data from the database contains speech marks or single quotes, which when changed to an input field will mess up the input html. How can I escape the html for each input field?