jQuery objects of the same element are not equal?

前端 未结 5 1639
梦毁少年i
梦毁少年i 2021-01-17 23:39

This must be something I\'m overlooking, but please look at the following page and JavaScript and tell me why, for everything that\'s holy, jQuery won\'t return true?

<
5条回答
  •  甜味超标
    2021-01-18 00:31

    Try this - Working Demo --> http://jsfiddle.net/mohammadAdil/tHjgN/

     if(t.is(s)) {
        console.log('yes');
     }
    

    http://api.jquery.com/is/

    Or with ===

    if (t.get(0) === s.get(0)) { //<--Compare DOM elements instead of jquery object's
        console.log('again yes');
    }
    

    Demo --> http://jsfiddle.net/mohammadAdil/tHjgN/1/

提交回复
热议问题