Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove second div with same class

Tags:

jquery

class

In my HTML are two divs with identical classes. If I want to remove the div by class, both of them get removed. How can I (whilst using Jquery) remove the second div by class? Is there a way for it to 'skip' the first div it finds?

The code looks like this:

<div class="wrapper">
  <div class="randomdiv">
    <div class="oneofthetwodivs">
    </div>
  </div>
  <div class="randomdiv"></div>
  <div class="randomdiv"></div>
  <div class="oneofthetwodivs">
</div>
like image 662
Brendan Avatar asked Feb 05 '15 13:02

Brendan


1 Answers

You could use eq() to target the second element with that class (it is zero based):

$('.oneofthetwodivs').eq(1).remove();
like image 56
dsgriffin Avatar answered Sep 23 '22 22:09

dsgriffin