Skip to content Skip to sidebar Skip to footer

Ignore Table Click Function When Clicking On A Link

I have a click method when the user taps a row in my table. $('.table > tbody > tr').click(function () { if ($(this).hasClass('info')) { $(this).removeClass('info

Solution 1:

Just check if a link is clicked with event.target and .closest() :

$('.table > tbody > tr').click(function (e) { //Catch event hereif($(e.target).closest('a').length) return; // Add thisif ($(this).hasClass("info")) {
        $(this).removeClass("info");
    }
    else {
        $(this).addClass("info");
    }
});

Solution 2:

You can stop the click event from propagating from the anchor

$('.table > tbody > tr a').click(function (e) { 
    e.stopPropagation()
});

http://jsfiddle.net/JkebH/

Post a Comment for "Ignore Table Click Function When Clicking On A Link"