I know there are many different ways for creating HTML elements in jQuery, but I’ve seen people either showing:
$("<div></div>", {attrs...})
or
$("<div/>", {attrs...})
as the primary methods for doing so.
I’ve found that
$("<div>", {attrs...})
works just fine too.
Why does no one ever show the third method? Are there potential problems with it? As far as the result it concerened, it looks much the same when I inspect element to see the created div.
Creating the html element with tag like
$('<div>'),$("<div>", {attrs...})is documented way of creating html elmenets check it here.When the parameter has a single tag (with optional closing tag or quick-closing) —
$("<img />")or$("<img>"),$( "<a></a>" )or$("<a>" )— jQuery creates the element using the native JavaScript createElement() function.