why $.isEmptyObject($('#id-does-not-exist-on-page')) returns false?

后端 未结 3 1480
梦谈多话
梦谈多话 2021-01-15 07:45

I\'m little confused by jQuery.isEmptyObject method.

$.isEmptyObject([]) -> returns true

but

$(\'#id-does-not-exist-

3条回答
  •  孤街浪徒
    2021-01-15 08:41

    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])

提交回复
热议问题