Skip to content Skip to sidebar Skip to footer

Identifying A Child Element Of A Clicked Target In Jquery

I'm trying to work out how I can right-click anywhere in the table, which has an event listener on the tr tag, and will pass the click() command down to the child button.

Solution 1:

You need to use jquery find method wich searches for first child instance at any depth

jQuery(".catcher").contextmenu(function(e) {
  $(this).find('button').click();
  returnfalse;
});
table {
  border: 1px solid red;
  width: 200px;
  height: 200px;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><table><trclass="catcher"><td><span><buttononclick="alert('it works!');">Button</button></span></td></tr></table>

Solution 2:

jQuery(".catcher").contextmenu(function (e) {
    //e.target.**FIND CHILD BUTTON**.click();
  $(e.target).find('button').click()
});
table {
  border: 1px solid red;
  width: 200px;
  height: 200px;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><table><trclass="catcher"><td><span><buttononclick="alert('it works!');">Button</button></span></td></tr></table>

wrap e.target in $() then use .find('button')

Solution 3:

Refer this here Qty is Class Name

($(e).parent().parent().find(".Qty").val()

Post a Comment for "Identifying A Child Element Of A Clicked Target In Jquery"