jquery: what does “$(this)” exactly mean?

this is a reference to the member that invokes the current function…

then you can wrap it in the jquery function $() to select it just like you would another selector.

So setInterval calls a anonymous function so it is not invoked by a referencable member, so it defaults to the window object.

save the this context in a variable and then use it internally like this…

$(document).ready(function(){
    $("#round").click(function(){
        var clicked = this;   //<----store the click context outside setInterval
        setInterval(function(){
            $(clicked).animate(  //<----------use it here
                {height: 250,
                width: 150,
                top:150,
                left: 425},
                {duration: 300}
                ).
            animate(
                {height: 200,
                width: 200,
                top:200,
                left: 400},
                {duration: 300}
            );
        }, 0);
    });
});

Leave a Comment