Cheerful evening, there is a list

<li value="1" par="0">1</li> <li value="2" par="1"> -- 2</li> <li value="3" par="2"> -- -- 3</li> 

When you click on the first element, you need to get an array of elements that have par = "1" hide them and their daughters, also in a loop, like a recursive function called. How to do it ?

Basically it is not clear just how to get an array, which then work

  • You can get an array like this: $ ('li [par =' + val + ']') - Ali

1 answer 1

 $(e => { $('ul').on('click', '[par]', function(e){ // Вот элемент, у которого атрибут par равен значению value у кликнутого li let child = $(`[par="${this.value}"]`); child.css({color: 'red'}); }); }); 
 li{cursor: pointer;} 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li value="1" par="0">1</li> <li value="2" par="1">-- 2</li> <li value="3" par="2">-- -- 3</li> </ul>