Disable a function on an old buttons

jquery disable button click event
disable/enable onclick event javascript
disable function in jquery
disable button javascript
check if button is disabled jquery
how to disable submit button after form submission in javascript
jquery disable button after click
jquery prop(disabled not working)

in my project i want to add programmatically certain elements buttons ,because every time a new button is added , The call is doubled to the same function for the oldbutton.

var btnElem ='<button type="button"class="doSomething">Button</button><br>';


function ActiveFunc(){
  $('.doSomething').on('click',function(){  
    alert('Clicked');
  });
}

$('#Add_Btn').on('click',function(){  
  $('#div_').append(btnElem);
  ActiveFunc();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button type="button" id="Add_Btn">AddBtn</button><br>
<div id="div_"></div>

This is because you add the event listener every time you add the button.

I would advice 1 event listener for this like so:

var btnElem = '<button type="button"class="doSomething">Button</button><br>';

$('body').on('click', '.doSomething', function() {
  alert('Clicked');
});

$('#Add_Btn').on('click', function() {
  $('#div_').append(btnElem);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button type="button" id="Add_Btn">AddBtn</button><br>
<div id="div_"></div>

How can I disable and enable other buttons in Javascript something , parentNode.getElementsByTagName('button'); for(i=0;i<buttons.length;i++){ buttons[i].disabled=true; } The problem with disabling buttons is that once they'​re disabled they're disabled. EDIt: As per a previous post. You will learn that either you should Enable the Action Keys within from BIOS or disable it. It totally depends that how you use the F1 to F12 function keys during the day.

Alice Yu is correct, but I would take a different approach and add onclick on the button and use that to call the function like so:

<button type="button" onclick="addButtonFunction();" id="Add_Btn">AddBtn</button>

and do the same on the dynamically added button

How to disable a button in jQuery dialog from a function , jQuery | grep() Method · How to call functions after previous function is completed To disable the button in a jQuery dialog from a function carried using jQuery  To disable, or enable, the function key (fn) in the BIOS, do the following steps. Press the power button to turn on the computer. Press the f10 key to open the BIOS setup window. Press the right-arrow or left-arrow keys to navigate to the System Configuration option.

Why not just add a button element with the class? No need to attach an event every time. Here's the solution, using ES6 syntax.

let btnElem = '<button class="doSomething">Click me</button>';

$(document).on("click", ".doSomething", () => {
  alert("Do something");
});

$(document).on("click", "#addBtn", () => {
  $('#div_').append(btnElem);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="addBtn">AddBtn</button><br>
<div id="div_"></div>

jQuery disable button, Using jQuery to disable a button has many advantages as it will allow you to enable and disable the button based on user interaction. You will easily be able to  How to Choose Whether Your Function Keys are F1-F12 Keys or Special Keys Chris Hoffman @chrisbhoffman Updated April 23, 2020, 2:45pm EDT Modern laptop and desktop keyboards have a multi-purpose set of keys in the “function” row.

Event Listeners are attached on a one off basis to a specific element. Which is why you are having multiple events...

var btnElem ='<button type="button"class="doSomething">Button</button><br>';


function ActiveFunc(){
  $('.doSomething').on('click',function(){  //this function is attaching an event listener to all elements with a class of doSomething.
  //event listeners are attached on an element basis despite your jquery selector targeting a class name
  //so on the third activation the first button now has 3 listeners, the second now has 2 listeners and the third one
    alert('Clicked');
  });
}

$('#Add_Btn').on('click',function(){  
  $('#div_').append(btnElem);
  ActiveFunc();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button type="button" id="Add_Btn">AddBtn</button><br>
<div id="div_"></div>

How to enable/disable an element using jQuery and , 1) Register enable() and disable() function with buttons to enable and disable to the previous example, we have two buttons btn_enable and btn_disable to  This article explains how to disable a function in Azure Functions. To disable a function means to make the runtime ignore the automatic trigger that is defined for the function. This lets you prevent a specific function from running without stopping the entire function app. The recommended way to disable a function is by using an app setting in the format AzureWebJobs.<FUNCTION_NAME>.Disabled.

You are adding the function to every element with the .doSomething class. Try something like this instead:

$('#Add_Btn').on('click',function(){ 
  btnElem.on('click', function() {
    //blah blah
  }); 
  var newButton = $('#div_').append(btnElem);
})

Enable/Disable multiple buttons in Kendo UI for jQuery Button , on Enable/Disable multiple buttons of Kendo UI for jQuery Button. when I try to enable/disable the buttons using the previous code, only the  From there click 'System Configuration' then 'Function Key Behavior'. Switch to 'Fuction Key First' then hit the 'Apply' box, then 'Exit'. Now the function keys will work normaly and you can hold 'Fn' to use the multimedia fuctions.

How to enable/disable next and previous buttons for pagination , I am not able to enable/disable next and previous pagination buttons. it works fine for first time but when i reportCompleted: function (status) { This code will let you submit the form once, then disable the button. Change the selector in the find() function to whatever button you'd like to disable. Note: Per Francisco Goldenstein, I've changed the selector to the form and the event type to submit. This allows you to submit the form from anywhere (places other than the button)

Enable/Disable jQuery buttons in Knockout with a Custom Binding , Still working on those jQuery buttons, trying to update old ASP. It would enable/​disable the underlying element that I had run the .button()  Enable or disable fn (function) or action keys mode. Change the action key setting from the BIOS Setup Utility. Press and hold the Power button for at least five seconds to turn off the computer. Turn on the computer and immediately press the f10 key repeatedly to open the BIOS Setup Utility.

Preventing Double Form Submission < JavaScript, Using JavaScript to disable form buttons and prevent double The difference from previous examples is the alert when the button is being  An administrator had a question about disabling ribbon and toolbar buttons: How can I disable the function "Edit Message" under Message, Actions, Other Actions? You can disable commands using group policy or by editing the registry. Group Policy is not limited to use by network administrators. The policy key that is used to lock out ribbon and

Comments
  • Possible duplicate of Event binding on dynamically created elements?
  • $('#div_').append(btnElem); will return the $('#div_') into the variable, so this logic will duplicate bind on that element.
  • @Taplar You're completely right - I wrote this too fast! Thanks for the heads up :) Hopefully I've fixed it.
  • btnElem is a string. Can't bind on a string, :)