there is a markup enter image description here

there is an event handler for pressing "span class = 'close'"

$("docement").ready(function () { $(".close").on("click",function (e) { var el = $(this).parent().children(".kek"); console.log(el.val()); *вывод тут* }); }); и тут мне выводит пустое место, я пытался даже использовать .show() / .hide, но значение все равно пустое. А если я использую классическое .value, то выводит вообще undefined! Что делать? 
  • console.log(el.parentNode); or console.log($(el).parent()); - Igor

2 answers 2

jQuery

 $("span").on("click", function() { console.log($(this).parent()); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="foo foo_1"><span>Click me</span></div> <div class="foo foo_2"><span>Click me</span></div> <div class="foo foo_3"><span>Click me</span></div> 

Vanilla js

 [...document.querySelectorAll(".foo > span")].forEach(item => { item.addEventListener("click", (e) => { console.log(e.currentTarget.parentNode); }); }); 
 <div class="foo foo_1"><span>Click me</span></div> <div class="foo foo_2"><span>Click me</span></div> <div class="foo foo_3"><span>Click me</span></div> 

  • thank you keep daw)) - Anton Tomashtik February

e.target returns a HTMLElement .

Elements have no parent property, there are parentNode and parentElement .

Since jQuery is already in use, you can use the parent method