Wanting to learn
Wanting to learn

Reputation: 468

trying to remove a class when image is clicked

I'm try to remove a class with jquery when a image is clicked but I can seem to get it to work. I'm using

 $(this).removeClass('.title');

to remove this class but it's not working.

 .title{
   font-size: 100%;
   top: -40px;
   color: white;
   left: 0%;
   position: absolute;  
   z-index: 1;
   }

Here's my JSFiddle.

Upvotes: 1

Views: 60

Answers (2)

krishwader
krishwader

Reputation: 11381

Its not

$(this).removeClass('.title');

Its

$(this).removeClass('title');

You must not use . when you're using addClass , removeClass and toggleClass. And as metioned by the other answerers, in your demo, the class title is not applied to li, but to the div. So you must do something like this to remove title :

$(this).find("div").removeClass('title');

Demo : http://jsfiddle.net/hungerpain/XYZZx/39/

Upvotes: 8

Ivan Chernykh
Ivan Chernykh

Reputation: 42196

In your case it is not enough to do removeClass("title") but you need even more:

$("div",this).removeClass('title');

Here it's working as you're expecting: http://jsfiddle.net/XYZZx/38/

Upvotes: 1

Related Questions