No, you did not miss anything. jQuery will happily take this and display the corresponding tag. I think a lot of people are confused because the docs suggest using an XHTML-compatible element.
However, according to some people, jQuery does not pass this directly to document.createElement()
. Rather, it runs the regex (or at least the last time I checked), and computes what actually goes to document.createElement()
.
What it seems to me is that there is no right or wrong way to create an element, since you are actually passing a string representation of some HTML element. Mr. Resig could just as easily have used $('div');
or $('HTML:DIV');
, or what he felt at that time. Instead, he decided to use an βHTML-like string that will correctly translate this regular expression into actual HTMLβ, and as such, all of the following values ββare equally valid:
$('<div>'); $('<div/>'); $('<div></div>');
... and are valid not because they may or may not meet XHTML requirements, but because the regular expression used can turn this into a valid HTML element.
source share