object contains a collection of DOM elements and behaves like a special array.
An empty jQuery
object is nothing but containing “no DOM elements” .
many element selector used in jQuery. The simplified selection syntax can be as
supplied expression (with or without criteria) to find out the matching
elements from DOM doesn't find any element(s) then jQuery returns an empty jQuery-object.
empty Object can be created as –
var emptyJqueryObject = $();
Note: Don't be confused that
if you wouldn't supply any selector then () will return you an empty object. jQuery()
or $() or $(“”) expects a context and if we do not supply any
context, ‘document' is considered as the default context. You can check it as-
var c = $();
alert( $.isEmptyObject(c) );
Output : False
object contains a collection of DOM elements and when filtered using some
selectors, this object contains “matched-elements” or “selected elements”. This
jQuery object behaves like an array (special array and not like native
length, we can access elements using numeric indices starting from 0 to
length-1. Here length is the length of this jQuery object. jQuery object can be
created with help of jQuery() or its alias $().
methods return the jQuery object itself
(except some destructive methods like find() and filter() that change the
object), so that method calls can be easily chained and minimize the code line.
$('div').css ('color','red').find ('.myCSSname').css ('color','yellow');
The above jQuery
code will find all DIV elements on document and apply the css and then inside
it find those elements whose class is “myCSSname” and apply the css on this
chaining. For chaining you can refer my other article on Chaining