Why is it important to use $(this) instead of re-selecting the class?
I am using a lot of animate and css editing in my code, and I know I can simplify it by using
Have a look at this code:
HTML:
JS:
$('.multiple-elements').each(
function(index, element) {
$(this).css('background-color', $(this).data('bgcol')); // Get value of HTML attribute data-bgcol="" and set it as CSS color
}
);
this refers to the current element that the DOM engine is sort of working on, or referring to.
Another example:
Hide me!
Hope you understand now. The this keyword occurs while dealing with object oriented systems, or as we have in this case, element oriented systems :)