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 8986695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:36:42+00:00 2026-06-15T21:36:42+00:00

I need a method to enable and disable any element. Disable meaning set the

  • 0

I need a method to enable and disable any element. Disable meaning set the opacity to 0.6 and remove the onClick callbacks. Enable meaning set the opacity to 1 and add the callback again.

My first two attempts failed miserably, the callback methods just got stacked and instead of running it once after each click the method was running more and more times.

function disableElement(element){
    var el = $('#'+element); 
    el.css('opacity','0.6');
    el.on('click',null);     //this doesn't work
            el.removeAttr('onClick'); // this doesn't help either.

}

function enableElement(element,callback){
    var el = $('#'+element); 
    el.css('opacity','1');
    el.on('click',callback);            
}

Then i tried using the el.data:

disableElement:function(element){
        var el = $('#'+element); 
        el.css('opacity','0.6');
        el.data('element-enabled','false');
        //el.click(function (){
        //  alert('disabled');
        //});           
    },
    
    enableElement:function(element,callback){
        console.log('enabling');
        var el = $('#'+element);
        console.log(el);
        if(el.data('element-enabled') == "true")
            return;
        console.log("setOpacity");   
        el.css('opacity','1');
        el.data('element-enabled','true');
        el.click(function(){
            if(el.data('element-enabled') == "true")
                callback();
        }); 
            
    }

Now they don’t stack, as long as I don’t disable it. If I disable and then enable it again, it gets stacked. Which means, if i run enableElement multiple times the callbacks don’t stack. But once I run disableElement and then enableElement, if i click in the item, it’ll happen twice.

Can achieve that somehow?

UPDATE

That was close. The off worked for me but i also had to remove it on the enableElement. Occasionally I have to call it twice, so it was still stacking. Finally this worked, thank you!

disableElement:function(element){
    var el = $('#'+element); 
    el.css('opacity','0.6');        
    el.off('click');

},

enableElement:function(element,callback){       
    var el = $('#'+element);
    el.off('click');                    
    el.css('opacity','1');      
    el.on('click',callback);    
        
}
  • 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-15T21:36:43+00:00Added an answer on June 15, 2026 at 9:36 pm

    To remove the event just use .off()

    el.off('click');
    

    To add the event back you can just do

    el.on('click',callback);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would I need to add to my OpenGL init method to enable depth
I need to enable/disable a WPF button based on the return of a method.
I need a method to disable user interaction with the application for certain calls
Why is Button.enable deprecated? I need to use the method of my button but
I need to Enable/Disable my SAVE button in real time based on data in
I need a method that creates an empty clone of an object in a
I need a method in JavaScript to escape all characters which are not (
I need a method to redirect my Mac's audio output to a different computer
I need a method to get the data from an external editor. def _get_content():
I need a method that can monitor each change in the user in an

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.