简体   繁体   中英

How to use .delegate with .closest?

$('.inputRadio').closest("td").click(function (e) {
    //some code
});

how to use delegate in the above function? Anyone can help?

You can solve this by calling .closest on $(this) inside the event handler:

$(document).delegate('.inputRadio', 'click', function () {
  var closestTd = $(this).closest('td');
  // some code
});

Note: You should use .on if your version of jQuery is >= 1.7 :

$(document).on('click', '.inputRadio', function () {
  var closestTd = $(this).closest('td');
  // some code
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM