Lieutenant Dan
Lieutenant Dan

Reputation: 8274

make hover to img tag with jQuery chaining

I'm currently trying this. But it isn't working..

$('.hover-button').hover(function() {
    $('.section.coolClass img').addClass('.hoverclass');
});

Because assuming it's attaching to the img tag and failing. Any ideas on how to achieve this?

YES. On hover out, the class needs to be removed..

Also, note: I am trying to achieve this:

section.coolClass img:hover {
  transform: scale(1.2); z-index: 3; cursor: pointer;
}

Upvotes: 0

Views: 47

Answers (2)

zgood
zgood

Reputation: 12581

You are using css when you should be using toggleClass. Like this:

$('.hover-button').hover(function() {
    $('.section.coolClass img').toggleClass('hoverclass');
});

css is used to add inline styles to your elements. When you want to add/remove classes to your elements use addClass, removeClass, and toggleClass. Also don't include the .

Upvotes: 4

mhodges
mhodges

Reputation: 11116

Try this:

$('.hover-button').hover(function() {
    $('.section.coolClass img').toggleClass('hoverclass');
});

Upvotes: 0

Related Questions