Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery click event on element not having a class

How would I make sure that this href element is will fire "click" event unless it does NOT have "disablelink" class.

DO NOT PROCESS:

<a class="iconGear download disablelink" href="#">Download</a>

PROCESS:

<a class="iconGear download" href="#">Download</a>

tried this without success:

    $("a.download").not(".disablelink").click(function (e) {
        alert('in');
        e.preventDefault();
    });
like image 873
ShaneKm Avatar asked Jan 19 '26 02:01

ShaneKm


1 Answers

This should work:

$("a.download:not('.disablelink')").click(function (e) {
    alert('in');
    e.preventDefault();
});

If the disablelink class is being added dynamically:

$(document).on('click', "a.download:not('.disablelink')", function (e) {
    alert('in');
    e.preventDefault();
});

Check this demo: http://jsfiddle.net/d3rXr/1/

like image 65
techfoobar Avatar answered Jan 21 '26 16:01

techfoobar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!