javascript - <img src="x" onerror="alert(\"hello\")" />) escaping quote is illegal? -


i trying play around escape character.

<img src="x" onerror=alert('hello'); />  <img src="x" onerror="alert(\"hello\")" /> 

the 2nd 1 produces illegal character in dev console. why? why can't use escape character?

demo: http://jsfiddle.net/h7nnk/1/

because \ not escape character in html.

<img src="x" onerror="alert(&quot;hello&quot;)" /> 

or, per @mplungjan's comment:

<img src="x" onerror="alert('hello')" /> 

or, better still:

<img src="x" id="derp" /> <script type="text/javascript">     document.getelementbyid('derp').addeventlistener("error",function() {         alert('hello');     },false); </script> 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -