Diego Diego - 8 months ago 16
Javascript Question

Delete all siblings to the right but not to the left JQUERY JAVASCRIPT

I'm building a breadcrumb and a button is added within a DIV as you go deep in the folders like:

<div id='breadcrumb-wrapper'><button id='uniqueId1'>FolderName1</button><button id='uniqueId2'>FolderName2</button><button id='uniqueId3'>FolderName3</button><button id='uniqueId4'>FolderName4</button></div>

Every button goes to its patch and I need to delete all the siblings to its right but not to its left when the user click it, if I use something like:


All siblings plus ALL elements go away from that node and that's not the idea. If I use something like:


All siblings including the first and the second one go away which as well It's not what I need to do, so how could I achive this?


Use nextAll on the element itself, not on the parent:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='breadcrumb-wrapper'>
  <button id='uniqueId1'>FolderName1</button>
  <button id='uniqueId2'>FolderName2</button>
  <button id='uniqueId3'>FolderName3</button>
  <button id='uniqueId4'>FolderName4</button>