How to escape html entities in JS?

0 like 0 dislike
9 views
Good day,

The given code gives the error "Uncaught SyntaxError: missing ) after argument list" . Looks like JS unfolds ' in quotes and because of this all breaks down. How to escape quotation marks and other html entitles in js?

function clickme(str){console.log(str);}Click
by | 9 views

2 Answers

0 like 0 dislike
It does not JS and the browser. After all, you use the html entity. This entity and are converted to text.

A simple shielding, like everywhere
Click
by
0 like 0 dislike
thank you, further question.

Suppose that the function clickme is passed to the custom text which will be inserted in html. In this case it is better to escape the parameters? to avoid XSS ?

\r\r\rfunction clickme(str)\r{\rdocument.getElementById("div-id").innerHTML = str;\r}\r\r\r\r\r
\rClick\r
by

Related questions

0 like 0 dislike
2 answers
asked May 20, 2019 by heyMyWay
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
5 answers
110,608 questions
257,186 answers
0 comments
33,773 users