Multi-select Row, but Not Hyperlink
Multi-select Row, but Not Hyperlink
Hi All,
I'm following the multi-select row example on the site and it's working fine, except that I've got columns that have hyperlinks in them (for edit, view, delete, etc). In those cases when I click the link, the row highlights for a moment, then my page loads.
Is there a way to not select/deselect the row if a hyperlink is clicked? I considered making columns that have links not clickable, but some columns have a lot of blank space and it's odd that you can't click in those cells (just not on the text). Is my only option to switch to checkboxes?
Thanks in advance!
I'm following the multi-select row example on the site and it's working fine, except that I've got columns that have hyperlinks in them (for edit, view, delete, etc). In those cases when I click the link, the row highlights for a moment, then my page loads.
Is there a way to not select/deselect the row if a hyperlink is clicked? I considered making columns that have links not clickable, but some columns have a lot of blank space and it's odd that you can't click in those cells (just not on the text). Is my only option to switch to checkboxes?
Thanks in advance!
This discussion has been closed.
Replies
To answer your question though, use this:
event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true;
...in the event handler for the checkbox or hyperlink as it were.
With regards to the stopPropagation, I don't currently have any event handler for the hyperlinks. Would I do something like-
[code]
$('#mytable tr td a').click(function(){
event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true;
});
[/code]
This table is built from an ajax call, so I would assume I'd have to use .live(), except that reading the jQuery event.stopPropagation() doc says that it would fire after it had already been propagated.
You almost have it. You need to pass the event to the handler as in this:
Fiddle: http://jsfiddle.net/atomofthought/h9U4M/
Full Screen: http://jsfiddle.net/atomofthought/h9U4M/embedded/result/
Regards,
Robert