Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:10:16+00:00 2026-06-15T08:10:16+00:00

Trying to figure out proper way to make a click event not fire on

  • 0

Trying to figure out proper way to make a click event not fire on the icon of a disabled link. The problem is when you click the Icon, it triggers the click event. I need the selector to include child objects(I think) so that clicking them triggers the event whenever the link is enabled, but it needs to exclude the children when the parent is disabled.

Links get disabled attribute set dynamically AFTER page load. That’s why I’m using .on

Demo here:(New link, forgot to set link to disabled)

http://jsfiddle.net/f5Ytj/9/

<div class="container">
    <div class="hero-unit">
        <h1>Bootstrap jsFiddle Skeleton</h1>
        <p>Fork this fiddle to test your Bootstrap stuff.</p>
        <p>
            <a class="btn" disabled>
                <i class="icon-file"></i>
                Test
            </a>
        </p>
    </div>
</diV>​

$('.btn').on('click', ':not([disabled])', function () { alert("test"); });​

Update:
I feel like I’m not using .on right, because it doesn’t take the $(‘.btn’) into account, only searching child events. So I find myself doing things like $('someParentElement').on or $('body').on, one being more difficult to maintain because it assumes the elements appear in a certain context(someone moves the link and now the javascript breaks) and the second method I think is inefficient.

Here is a second example that works properly in both enabled/disabled scenarios, but I feel like having to first select the parent element is really bad, because the event will break if someone rearranges the page layout:

http://jsfiddle.net/f5Ytj/32/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:10:17+00:00Added an answer on June 15, 2026 at 8:10 am

    Don’t use event delegation if you only want to listen for clicks on the .btn element itself:

    $('.btn').on('click', function() { 
        if (!this.hasAttribute("disabled"))
            alert("test");
    });​
    

    If you’d use event delegation, the button would need to be the matching element:

    $(someParent).on('click', '.btn:not([disabled])', function(e) {
        alert('test!!');
    });​
    
    • Demo

    Or use a true button, which can really be disabled:

    <button class="btn" [disabled]><span class="file-icon" /> Test</button>
    
    • Demo, disabled.

    Here, no click event will fire at all when disabled, because it’s a proper form element instead of a simple anchor. Just use

    $('.btn').on('click', function() { 
        if (!this.disabled) // check actually not needed
            this.diabled = true;
        var that = this;
        // async action:
        setTimeout(function() {
            that.disabled = false;
        }, 1000);
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out the proper way to use NSManagedObjectContexts when you
I'm trying to figure out the proper way to write this using Razor syntax:
I'm trying to figure out the proper PBP approved way to process a multi
Just trying to figure out the proper and safer way to execute mathematical operation
I'm still trying to figure out what is the proper way to add a
I am trying to figure out what is the proper way to remove an
I am trying to figure out a 'proper' way of sorting UTF-8 strings in
I'm trying to figure out the proper way to display arrays of objects, indexed
Trying to figure out why my silverlight app suddenly just displays nothing (right click
Trying to figure out how to type (via events not set the value) on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.