Let's say I have a page with multiple h2 tags. I want to get all the h2 tags that do not have a css class.
So in this example:
<h2>Headline 1</h2>
<p>content 1</p>
<h2 class="some-class">Headline 2</h2>
<p>content 2</p>
<h2>Headline 3</h2>
<p>content 3</p>
<h2 class="another-class">Headline 4</h2>
<p>content 4</p>
I want to get the h2 elements wrapping "Headline 1" and "Headline 3" in the above example.
Doing this:
var h2_tags = $("h2");
Will result in getting all H2's, which I don't want. How can I get only the ones without any CSS class?
[class]
is a valid selector, so you can just do this:
$('h2:not([class])')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With