I have this line of code in my javascript (its jquery)
$('#myobject').append("<img width='225' title='"+addslashes(post.title)+"' src='"+urlvisual+"' />");
the addslashes function was pulled from another post on here about escaping quotes
function addslashes( str ) {
return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}
but the result is still breaking the title attribute, any suggestions?
Since we’re using jQuery anyway, we could use their element-building syntax:
Cleaner code, and no escaping necessary 🙂