F
F
Frank_Sidebottom2018-02-06 17:05:56
JavaScript
Frank_Sidebottom, 2018-02-06 17:05:56

Parent ID based on child?

Hello! The task is this: you need to find out the ID of the button's parent. I do so. I press the button. Next, I find out the parent of the pressed button. Next, I translate the parent into a string (I'm not sure what I'm doing right). Then I display the parent's ID through the alert. It prints undefined :( Please correct me.

$('table').on('click','button', function(){
  $per = $(this).parent();
  $lel = $.param($per);
  alert($lel).attr('id');

});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-02-06
@Frank_Sidebottom

$('table').on('click','button', function(){
  var $parent = $(this).parent();
  alert($parent.attr('id'));
});

PS When declaring variables, use the var keyword if you don't want the variable to be global.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question