JQuery: help with ".live" and ".scroll"

If I have the following jQuery:

$('#div1, #div2').scroll(function() { my_function($(this)); });

or

$('#div1, #div2').live('mouseover',function(){ my_function($(this)); });

What does it mean $(this)?

Is this a DOM object from DIV1 or DIV2? Or is it the HTML of this div?

What does "this" mean in the code above?

+3
source share
4 answers

thisis the DOM element on which the event was fired, in this case #div1or #div2.

$(this)- a jQuery call to wrap DOM element in the jQuery wrapper, so you can use jQuery functions (eg .text(), .bind(), .load()).

+8
source

thisrepresents the DOM element that triggered the event, either #div1, or #div2.

+2

this DOM, (#div1, #div1,...)

+2

jQuery:

http://api.jquery.com/jQuery/#using-dom-elements

jQuery this DOM, . DOM, , #div1, #div2.

lonesomeday, jQuery , jQuery. $(this). : " DOM jQuery".

: this - . , :

$(function() {
    $('#div1').click(function() {
        var myThis1 = this;
        $('.divs').each(function() {
            var myThis2 = this;
        });
    });
});

myThis1will be the DOM object for #div1, but the .each()context changes inside your call this. myThis2on each cycle a DOM object will be set for some element with a class divs. Just something to pay attention to :)

+2
source

Source: https://habr.com/ru/post/1773942/


All Articles