A jQuery object contains a collection of DOM elements and behaves like a special array.
An empty jQuery object is nothing but containing “no DOM elements” .
There are many element selector used in jQuery. The simplified selection syntax can be as –
If our 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.
Also, an 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
Many jQuery 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. Example –
$('div').css ('color','red').find ('.myCSSname').css ('color','yellow');