user1765862
user1765862

Reputation: 14145

remove css class from mutiple html elements

On html page I have multiple elements like,

<a class="myInput red  selected" selectable="">1</a>
<a class="myInput blue selected" selectable="">2</a>

point is that I could have many different myInput classes like red, blue, green, ... Now I want on certain event to remove all selected classes from entire document.

I know that I should use .removeClass("selected") but I dont know how to apply on whole document to many elements

Upvotes: 0

Views: 58

Answers (4)

Steevan
Steevan

Reputation: 826

You can check with the code.

$(selector).removeAttr(attribute)

you can refer the below link too.

Link

Upvotes: 1

Jai
Jai

Reputation: 74738

You can do this:

$('.myInput.selected').removeClass('selected');

it only removes the selected css class from the myinputs and which has the class selected.

Upvotes: 3

Naveen Chandra Tiwari
Naveen Chandra Tiwari

Reputation: 5123

You can use each loop like this as well :-

$('.selected').each(function(){
    $(this).removeClass("selected");
});

Upvotes: 1

Rory McCrossan
Rory McCrossan

Reputation: 337560

You can find all .selected elements and remove the class like this:

$('.selected').removeClass('selected');

If there are multiple .selected elements found in the document jQuery will internally loop over all of them for you and change the class.

Upvotes: 6

Related Questions