V
V
Vitaly2015-09-26 19:28:01
JavaScript
Vitaly, 2015-09-26 19:28:01

How to find all following elements outside the parent?

So. There is a form with elements, and groups of elements enclosed in blocks.
The form also has several hidden fields that open when you click on the corresponding checkboxes and radio buttons. There are quite a lot of such fields, so it makes no sense to make a script for each separately.
I wrote this simple version:
jsbin.com/niqanucido/edit?html,css,js,output

But it doesn't work because the nextAll() function only looks for sibling elements.

The idea is that when changing the property of a checkbox or radio button with a certain class, there should be a set of elements following the button being changed, and the first of this set should be animated.

We need an analogue of nextAll (), which is looking outside of the parents.

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-09-26
@Tratatuy

//Найдет все подходящие элементы среди потомков элементов, 
//идущих после текущих

$.fn.nextTreeAll = function(selector){
  var next = this.nextAll();
  next.map(function(e){
      return $(e).find(selector);
  });
}

Example:
<div class="test" id="one"></div>
<div class="test" id="two">
   <div class="test" id="three"></div>
</div>

$("#one").nextTreeAll(".test"); 
//Результат - только блок #three

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question