Nicolas Bocquel Nicolas Bocquel - 27 days ago 7
jQuery Question

Jquery, $(this) outside function

I would like to trigger a function inside an

each loop
.
The problem comes from the
$(this)
which is outside the
each loop


function look () {
$(this).css("color","blue");
};

$(".text").each(function(){

look();
// other functions()
//...
});


I know I can place my
$(this)
, inside the
each loop
, but I would like to proceed like this because I have many small functions to place. How can I do ? Thanks. Nicolas.

Answer

Try this:

function look (el) {
    el.css("color","blue");
};

$(".text").each(function(){

    look($(this));

});