javascript - jQuery: Prevent click on sub-element's class: redirect page on tr click EXCEPT certain td -
javascript - jQuery: Prevent click on sub-element's class: redirect page on tr click EXCEPT certain td -
i've been searching 30 minutes already, apologize if missed reply already. i've seen lot of close ones, none quite this.
i have imported javascript function used in several files. makes table row has clickable-row class redirect href attribute, thereby making whole row deed anchor tag.
however, on pages i'll have on td populated checkbox, want able click without page redirecting (so can select multiple rows in table).
here current function:
jquery(document).ready(function() { jquery('.clickable-row').click(function() { window.document.location = jquery(this).attr('href'); }); }); i want following, doesn't work:
jquery(document).ready(function() { jquery('.clickable-row').click(function() { if(!jquery(this).closest('td').hasclass('skip-click')) { window.document.location = jquery(this).attr('href'); } }); }); any ideas on how handle this?
you need utilize e.target.
this within handler refer .clickable-row element, not element triggered click. target property of event object homecoming element triggered event.
jquery(document).ready(function ($) { $('.clickable-row').click(function (e) { if (!$(e.target).closest('td').hasclass('skip-click')) { window.document.location = jquery(this).attr('href'); } }); }); javascript jquery html onclick click
Comments
Post a Comment