Given the following HTML:
<h2><span>1</span><span>2</span></h2>
<h2><span>1</span><span>2</span></h2>
<h2><span>1</span><span>2</span></h2>
<h2><span>1</span><span>2</span></h2>
I would like to remove the first span element from all the h2 elements.
I tried the following which only remove the first span from the first h2:
$("h2 span:first").remove();
$("h2 span").first().remove();
Try using the :first-child selector:
$("h2 span:first-child").remove();
Try this
$("h2").each(function(){
$(this).find("span:first").remove();
});
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