I\'m little confused by jQuery.isEmptyObject method
.
$.isEmptyObject([])
-> returns true
but
$(\'#id-does-not-exist-
because $('#id-does-not-exist-on-page')
returns a selector that matches nothing not an empty object which would be {}
According to the jQuery documentation (isEmptyObject) :
The argument should always be a plain JavaScript Object as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers
From isEmptyObject,
Check to see if an object is empty (contains no properties)
but,
$('#id-does-not-exist-on-page')
still has properties.
$('#id-does-not-exist-on-page').addClass('abra_ka_dabra')
// valid
[].addClass('abra_ka_dabra');
// TypeError: Object has no method 'addClass'
So,
try this instead
$.isEmptyObject($('#id-does-not-exist-on-page')[0])