-1

I'm trying to use $(this) inside a function, inside a .each loop but it's not selecting the correct element. I'm obviously doing something wrong. This is a basic version of what I'm trying to do. This is just to get me to the next stop, the below code really doesn't do much. I'm just trying to get better at making plugins and dealing with functions and variables and stuff.

$('.pixel-looper').each(function() {

    function fxNoneNext() {
        $(this).css('background', 'red');
    }

    $(this).find('a').bind('click', function() {
        fxNoneNext();
        return false
    });

});

1 Answers1

0

Always play safe...

$('.pixel-looper').each(function() {
    var self = this;
    function fxNoneNext() {
        $(self).css('background', 'red');
    }

    $(self).find('a').bind('click', function() {
        fxNoneNext();
        return false
    });

});
void
  • 33,471
  • 8
  • 45
  • 91