I'm am looking for a JavaScript equivalent for this (Java) code: org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(String)
So I can use it in JavaScript like:
loop ... foo = something;
elem.setAttribute("onclick", "bar(event, 'this:" + used_here(foo) + "');");
foo = something else;
repeat loop
So what is missing here is the function used_here(), which would properly escape its parameter according to JavaScript string rules.
Is there such a function that is standard (supported by major browsers) ?
--
Explanation for false duplicate: This is not about HTML escaping.
So NOT THIS: " -> "
But this: " -> \"