jQuery and HTML Comments
jQuery and HTML Comments
Hello,
I am new to jQuery, and I noticed a problem in the way it renders HTML comments.
For example, if I open the following HTML file in a web browser:
<html>
<head>
<title>jQuery Test</title>
<script type="text/javascript" src="jquery-1.11.3.min"></script>
</head>
<body>
<h1 id="htmlWithComment" <!-- onclick="alert('Commented HTML was clicked.');"-->>HTML with Comment</h1>
</body>
</html>
The text inside the <h1> tag gets rendered, but is preceded by a greater than (>) sign.
I inspected the HTML using Firefox, and it showed me something like this:
<h1 id="htmlWithComment" <!--="" onclick="alert('Commented HTML was clicked.');" --="">>HTML with Comment</h1>
Apparenty, the HTML is being modified as it is rendered, which affects any comments in the code. I ran this test with jQuery 2 and got the same result. I was able to reproduce this using IE 8, Chrome, and Firefox.