jQuery object equality

前端 未结 7 1836
醉梦人生
醉梦人生 2020-11-22 14:37

How do I determine if two jQuery objects are equal? I would like to be able to search an array for a particular jQuery object.

$.inArray(jqobj, my_array);//-         


        
7条回答
  •  暖寄归人
    2020-11-22 14:52

    The $.fn.equals(...) solution is probably the cleanest and most elegant one.

    I have tried something quick and dirty like this:

    JSON.stringify(a) == JSON.stringify(b)
    

    It is probably expensive, but the comfortable thing is that it is implicitly recursive, while the elegant solution is not.

    Just my 2 cents.

提交回复
热议问题