HTML:

<div class="basket_price_block"> <img src="images/personal_cabinet/basket1.png" class="basket_price_image" alt="" /> <div class="basket_price"> <span class="product_price" data-unitprice="4500">4500</span> <span>USD</span> </div> <div class="selected_basket_product"> <span class="basket_minus_unregistered"> - </span> <input class="basket_number_unregistered" name="basket_number" value="1" /> <span class="basket_plus_unregistered"> + </span> </div> <div class="clear"></div> </div> 

How to get to the first span from the basket_price block by clicking on any child of the selected_baset_product block?
Suppose I click on - (that is, this is the target ), then selected_basket_product is the parentNode , and then what?

  • childNodes ? learn.javascript.ru/traversing-dom - user194374
  • So it works: $(this).parent().siblings('.basket_price').find('span.product_price'); ? - cyadvert
  • I would be on js. But using childNodes then img 'this is childNodes [1] basket_price , and if you choose via [2] then in concol, #text - ddeadlink writes
  • @dirk using jQuery is also “on JS” because the jQuery library is written in JS. It would be more correct to say "without jQuery". - Regent

1 answer 1

If a

 <span class="basket_minus_unregistered" onclick="getToPrice(this);"> - </span> 

that

 function getToPrice(el) { console.log(el.parentNode.previousElementSibling.children[0]); } 

Give you

 <span class="product_price" data-unitprice="4500">4500</span> 

Will fit?

  • helped, thanks! but along the way the question arose, if you choose through childNodes then why childNodes[1] is img and basket_price is `childNodes [3] - ddeadlink
  • not sure. Maybe you have a space there or else as an "invisible" sign that the DOM sees? - cyadvert
  • 2
    If my answer is yours, please click the checkbox to mark as answered. "Not self-interest for the sake of", but only to increase the number of answered questions in the community :) Thank you - cyadvert
  • @dirk use .children instead of .childNodes if you do not need to consider text and comments. - Regent
  • @Regent. Thank. Answer corrected - cyadvert