Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove class from parent element with jQuery?

I can't figure out how to remove class from a parent element, basically I have a <audio> tag (from now on referred to as this) which is inside a div with class="playing" how can I remove this class?

tried this, but than understood that it will remove class from audio element not it's parent div:

this.removeClass("playing");
like image 511
Ilja Avatar asked Apr 16 '13 20:04

Ilja


People also ask

How to remove the class using jQuery?

jQuery removeClass() Method The removeClass() method removes one or more class names from the selected elements. Note: If no parameter is specified, this method will remove ALL class names from the selected elements.

How do you remove a class in CSS?

To add the CSS classes to an element we use addClass() method, and to remove the CSS classes we use removeClass() method.

How to replace classes in jQuery?

In jQuery, to replace one class properties with another, there is a function called replaceClass() through which it takes in two different class names the first class name is specified as a class which should be replaced with the second class name that is specified as the second parameter in the function, where it ...


2 Answers

this.parent().removeClass("playing");
like image 67
Uncle Iroh Avatar answered Sep 27 '22 21:09

Uncle Iroh


$(this).closest('div').removeClass("playing")

or

$(this).closest('div.playing').removeClass('playing')
like image 44
Schleis Avatar answered Sep 27 '22 21:09

Schleis