0

I have following very basic code. Please see the snippet below. If you inspect the element Test, you get follwoing output in firefox and chrome:

 <a href="#" onclick="myTestFunction(23, " ku="" nti");"="">Test</a>

A understand, that if I do not escape double quotes, the code will not work. And i also figured out that escaping with backslashes does not work. Instead we should use &quot;

I just what to know, what is the logic browsers treat the js code below and especially i want to know why are there appearing all those extra dobule quotes and =?

Thank you

$('#container').append('<a href="#" onclick="myTestFunction(23, "ku nti");">Test</a>');

function myTestFunction(){

  alert('myTestFunction');

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<div id="container" ></div>
Tornike Shavishvili
  • 1,244
  • 4
  • 16
  • 35
  • 1
    Don't use `onclick` attributes. Bind event handlers with (since you are using jQuery anyway) jQuery's `on`. – Quentin Nov 14 '18 at 12:18
  • @Pete You can see my code in the snippet. Please run sippet and inspect the element `Test`The code you mentioned is what browser outputs if you inspect the element. I am aware about single quotes and escaping. I just want to understand what is the logic browsers treat my html code and especially i want to understand why are there appearing all those extra dobule quotes and =? – Tornike Shavishvili Nov 14 '18 at 12:27
  • 1
    It's just error recovery for what looks like a new attribute. – Quentin Nov 14 '18 at 12:28

0 Answers0