Get table id by click in td using jQuery

本秂侑毒 提交于 2019-12-01 04:45:10

In the click handler you can use .closest()

$(this).closest('table').attr('id')

$("#tableID").on("click","input[type='text']",function(){

$(this).closest('table').attr('id');

});

reference closest()

You should delegate event to avoid multiple handlers, and then use delegateTarget to target current TABLE:

$('table').on('click', 'input', function (e) {
    alert(e.delegateTarget.id);
});

You can use

$('#tdId').click(function(){
    $(this).parents('table').attr('id');
});

it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!