I see people creating HTML elements in jQuery in two different ways:
$('<element>')
and
$('<element />')
I am curious which one is "more correct". I see the obvious advantage to the first one as being just simply less to type. Does it make a difference at all which one is used?
jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.
When a jQuery object is passed to the $() function, a clone of the object is created. This new jQuery object references the same DOM elements as the initial one.
append() & . prepend() .append() puts data inside an element at the last index; while. . prepend() puts the prepending element at the first index.
There is no difference, as seen in the source code, line 30 & line 121:
/* Line 30*/ rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, /* Line 121 */ // If a single string is passed in and it's a single tag // just do a createElement and skip the rest ret = rsingleTag.exec( selector );
The following are equivalent:
<a></a>
<a />
<a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With