What's the difference between '$(this)' and 'this'?

前端 未结 7 1568
面向向阳花
面向向阳花 2020-11-21 07:18

I am currently working through this tutorial: Getting Started with jQuery

For the two examples below:

$(\"#orderedlist\").find(\"li\").each(function          


        
7条回答
  •  一生所求
    2020-11-21 08:05

    Yes you only need $() when you're using jQuery. If you want jQuery's help to do DOM things just keep this in mind.

    $(this)[0] === this
    

    Basically every time you get a set of elements back jQuery turns it into a jQuery object. If you know you only have one result, it's going to be in the first element.

    $("#myDiv")[0] === document.getElementById("myDiv");
    

    And so on...

提交回复
热议问题