admin管理员组文章数量:1425913
I have a html table in which rows and columns are adding dynamically.
Create dynamic row
var row = tableHolder.insertRow(0);
row.id = "row_0";
Create a cell
var cell = row.insertCell(0);
cell.id = "cell_0"
Now I need to attach a click event on the dynamically created row.
row.addEventListener('click', function(evnt) {
openPopup();
}, false);
A popup will open on click on the row.
Now I want when user click on first cell of every row, click event should not be fired and popup will not open.
I have a html table in which rows and columns are adding dynamically.
Create dynamic row
var row = tableHolder.insertRow(0);
row.id = "row_0";
Create a cell
var cell = row.insertCell(0);
cell.id = "cell_0"
Now I need to attach a click event on the dynamically created row.
row.addEventListener('click', function(evnt) {
openPopup();
}, false);
A popup will open on click on the row.
Now I want when user click on first cell of every row, click event should not be fired and popup will not open.
Share Improve this question asked Jan 16, 2014 at 5:09 Rahul JainRahul Jain 6585 silver badges22 bronze badges 2- you don't mind jQuery solution right – Arun P Johny Commented Jan 16, 2014 at 5:10
- 3 try $(row).on('click', 'td:not(:first-child)', openPopup); – Arun P Johny Commented Jan 16, 2014 at 5:10
3 Answers
Reset to default 3You can use :gt selector in jquery to add click event on other rows.
Checkout the following link : http://api.jquery./gt-selector/
If you have a table with id="mytable"
then you can use jQuery's on()
method to listen for events on the table which occur on any cell except the first one in each row. The reason for binding to the table is so that dynamicly created rows will still trigger the event (since the event will bubble up to the table).
// Listen for click event on anything but first cell in each row within #mytable
$('#mytable').on('click', 'td:gt(0)', function() {
alert('Got click on anything but the first cell');
});
// Dynamically create row for demonstration
$('#mytable').append('<tr><td>Cell 1</td><td>Cell 2</td></tr>');
Here's a fiddle: jsfiddle Click on cell 1 and you will find no event fired, click on the second cell and the alert will appear.
Try this JQuery Solution
$('table tr td:not(:first-child)').click(function () {
openPopup();
});
本文标签: javascriptClick on table row except first cellStack Overflow
版权声明:本文标题:javascript - Click on table row except first cell - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745456481a2659125.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论