I use event delegation to display ,on click,a popup with detailed info on each TR of a table. However, the TR has some actual开发者_开发知识库 links, and I need to avoid showing the popup if a link is being clicked. (so show the popups only when the user clicks on a portion of the TR that is not a link. can anyone point me into the right direction? thanks.
you need to cancel propagation on all links in the table:
$('table').delegate('td', 'click', function (e) {
// do some code
});
$('table').delegate('a', 'click', function (e) {
e.stopPropagation();
});
EDIT: in a single delegate, somthing like this (not tested!):
$('table').delegate('td', 'click', function (e) {
if (e.target.nodeName.toLowerCase() == 'a') {
e.stopPropagation();
}
// do some code
});
You can use method chaining to reduce the code, but the credit is all goes to @Shlomi Komemi
$('table').delegate('td', 'click', function (e) {
// do some code
}).delegate('a', 'click', function (e) {
e.stopPropagation();
});
精彩评论