I saw this in some code:
$("<p/>").append("<div>something</div>").appendTo("body");
and noticed that it automatically closed the p tag in the generated HTML :
<p><div>something</div></p>
I’ve never seen the selector syntax $("<p/>") before. Is this mistake (and Chrome is just guessing what it should be) or is this a feature of jQuery’s selector syntax?
The
$function is heavily overloaded, even having two functionalities for strings. If the string is a CSS selector, it will return an object containing the matching elements from the document. If you open with<, it will create the element. jQuery is not creating a tag, however. Elements belong the DOM, tags belong to HTML, which is a serialization of the DOM.When you serialize the document, you will wind up with:
which shows each element containing its children.
If your markup looks like this:
<p/><div>something</div>, then thepanddivelements are siblings. That would happen if they were appended to the same parent: