var slides = $(".promo-slide");
slides.each(function(key, value){
if (key == 1) {
this.addClass("first");
}
});
Why do I get an error saying:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'addClass'
From the above code?
Inside jQuery callback functions,
this(and alsovalue, in your example) refers to a DOM object, not a jQuery object.BUT: In your case, this is easier:
And when all
.promo-slideelements in the same container, a solution in pure CSS is even easier:As an aside, I find it a useful convention to prefix variables that contain a jQuery object with a
$: