var s = $("<li><a href='index.html'><h3>hello</h3></a></li>");
alert(s.html());
Shows that the li element is not being created. Why?
var s = $("<li><a href='index.html'><h3>hello</h3></a></li>");
alert(s.html());
Shows that the li element is not being created. Why?
The s
is the <li>
element. Its inner HTML is what you're fetching with .html()
.
You can prove this with: alert(s.get(0).tagName);
In an HTML document, .html()
can be used to get the contents of any element. If the selector expression matches more than one element, only the first match will have its HTML content returned. Consider this code:
$('div.demo-container').html();
In order for the following 's content to be retrieved, it would have to be the first one with class="demo-container" in the document:
<div class="demo-container">
<div class="demo-box">Demonstration Box</div>
</div>
The result would look like this:
<div class="demo-box">Demonstration Box</div>