jquery - How to properly escape special characters, when setting in element attribute -
i getting values backend , making group of checkboxes, 1 of value not setting check box..
the test reads this: "french (cote d'ivoire)"
but in output getting result this:
<label><input value="french (cote d" ivoire)'="" type="checkbox">french (cote d'ivoire)</label>
i understand that, "'" - have scape. did replace work, still issue not fixed,
here try:
$.map(data["alllocales"], function(value, i){ var name = value.name; name.replace("'", """) tried name.replace("'", "\'") - no luck if(i % 5 === 0 ){ col0 += "<label><input value='"+ name +"' type='checkbox' />"+name+"</label>" }else if(i % 5 === 1){ col1 += "<label><input value='"+ name +"' type='checkbox' />"+name+"</label>" }else if(i % 5 === 2){ col2 += "<label><input value='"+ name +"' type='checkbox' />"+name+"</label>" }else if(i % 5 === 3){ col3 += "<label><input value='"+ name +"' type='checkbox' />"+name+"</label>" }else if(i % 5 === 4){ col4 += "<label><input value='"+ name +"' type='checkbox' />"+name+"</label>" } })
how escape "'" - single cote properly, , in case of other special characters
$, &,%
if in future how handle scenarios..?
use $(element).attr(attrname, value)
modify attribute, , $(element).text(value)
text content.
do not manipulate/concatenate html bad code lead security issues.
Comments
Post a Comment