There is a div parent in which a large number of child divs lie. With this design, I get the number of the child div, which was clicked:

document.querySelector('#main').addEventListener("click", function(evt){ log = [].indexOf.call(this.children, evt.target); }); 

Then, using evt.target, I can change the content of the div I clicked on:

 evt.target.innerHTML = "lorem ipsum"; 

Suppose that I recorded the number 32 in the log variable (which corresponds to the 32nd div in the parent block), but now I want to change the innerHTML property of the next div, for example, number 33 (well, or 1 44). Can I get some sort of event.target using the div number, so that I can change the innerHTML value in it?

    1 answer 1

    Probably something like this:

    I made an array of descendants here and took the element at the index + 2

     let log_2 = [].slice.call(this.children)[log+2]; 

    However, this approach is fraught with rake. it is better to use ids

     <div id="main"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> <script> document.querySelector('#main').addEventListener("click", function(evt) { let log = [].indexOf.call(this.children, evt.target); let log_2 = [].slice.call(this.children)[log+2]; evt.target.innerText = "target"; log_2.innerText = "target + 2"; }); </script>