tags:

views:

23

answers:

3

I have HTML like this:

<div id="Div1">...</div>
<div class="someClass">...</div>
<div id="Div2">...</div>
<div class="someClass">...</div>
<div id="Div3">...</div>
<div class="someClass">...</div>

So I have unique DIVs but also some that are indistinguishable from each other. I want to remove a div and the one below it, for example I want to remove Div2 and the someClass below it to end up with:

<div id="Div1">...</div>
<div class="someClass">...</div> <!-- That is the one after Div1 -->
<div id="Div3">...</div>
<div class="someClass">...</div>

I'm assuming the Next Siblings selector ~ would help, but that removes all. Trying to use :first did not do anything.

$("#Div2 ~ .someClass:first").remove();
+2  A: 

Try

$("#Div2 ~ .someClass").first().remove();

You can also use the next adjacent selector:

$("#Div2 + .someClass").remove();
SLaks
+1  A: 

Another fun way to do the same thing

$("#Div2").next().remove().end().remove();
Nikita Rybak
+1  A: 

To be more innovative:

$("#Div2").next().andSelf().remove()
SLaks