Jquery, how to escape quotes
Posted
by
Sandro Antonucci
on Stack Overflow
See other posts from Stack Overflow
or by Sandro Antonucci
Published on 2011-06-25T00:17:40Z
Indexed on
2011/06/25
8:22 UTC
Read the original article
Hit count: 179
I'm using a simple jquery code that grabs html code form a tag and then puts this content into a form input
<td class="name_cat" ><span class="name_cat">It's a "test" </span> (5)</td>
jquery gets the content into span.name_cat
and returns it as It's a "test"
.
So when I print this into an input it becomes
<input value="It's a "test"" />
which as you can imagine will only show as It's a
, the following double quote will close the value tag.
What's the trick here to keep the original string while not showing utf8 code in the input?
Jquery code
$(".edit_cat").click(function(){
tr = $(this).parents("tr:first");
id_cat = $(this).attr("id");
td_name = tr.find(".name_cat");
span_name = tr.find("span.name_cat").html();
form = '<form action="/admin/controllers/edit_cat.php" method="post" >'+
'<input type="hidden" name="id_cat" value="'+id_cat+'" />'+
'<input type="text" name="name_cat" value="'+span_name+'" />'+
'<input type="submit" value="save" />'+
'</form>';
td_name.html(form);
console.log(span_name);
}
);
I basically need html()
not to decode Utf8
© Stack Overflow or respective owner