robi
robi

Reputation: 31

use removeClass() on selected class

I have a DOM element with 2 classes attached.

I wanted to know if I can call the element with one of the classes, and remove the other class attached.

Let's say this is the code:

<span class="leave stay"> a </span>

and the jQuery is :

$('.stay').removeClass('leave');   

It seems like it is impossible.

Do you have an idea why it ain't working?

Thanks, robi

Upvotes: 1

Views: 191

Answers (1)

Nick Craver
Nick Craver

Reputation: 630379

What you have works, just make sure it's inside a document.ready handler (so it runs once the DOM is loaded, and your elements are there to be found), like this:

$(function() {
  $('.stay').removeClass('leave');  
});

You can test it here.

Upvotes: 3

Related Questions