jQuery objects of the same element are not equal?

前端 未结 5 1592
梦毁少年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:18

    You had your script in the but the element

    hello1

    in .

    First you should use $(document).ready() to make sure the content is loaded. Then check if they are equal using .is().

    $(document).ready(function() {
    
            var t = $('.test');
            var s = $('.test');
    
            console.log(t);
            console.log(s);
    
            if (t.is(s)) {
                console.log('yes');
            }
    });
    

    Compare the examples with and without the .ready() function.

提交回复
热议问题