jQuery objects of the same element are not equal?

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

    This could help you:

    var test = document.getElementById('test') //returns a HTML DOM Object
    var test = $('#test') //returns a jQuery Object
    var test = $('#test')[0] //returns a HTML DOM Object
    

    So (like limelights told you) use this:

    if (t[0] === s[0]) {
        console.log('yes');
    }
    

    Also it is good practice to use

    $(document).ready(function(){
    
    
    });
    

    around your code.

提交回复
热议问题