Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove a specific class from an element in HTML

I want to remove a class from a nested element in HTML.

<div class=sample>

<p>This should have the class as sample</p>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<p>This should not have the class as sample</p>

</div>

In the above snippet, I dont want to let the second <p> element to have the class sample. How can i do so?

>Solution :

You might like to try playing with the :not pseudo selector combined with :nth-child

.sample > p:not(:nth-child(2)){
  color:red;
  background:yellow
}
<div class='sample'>

  <p>This should have the class as sample</p>

  <p>This should not have the class as sample</p>

</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading