0

I have a disabled button I want to click with Javascript. The following function works in Chrome but not in Firefox.
The problem with Firefox: Firefox javascript is too slow.
The button is still disabled if the code wants to click it. How to click the button when it is enabled?

function enable_and_click() {
    document.getElementById('button1').disabled=false;
    document.getElementById('button1').click();
}
2
  • 1
    I can't seem to reproduce the problem. jsfiddle.net/zMnDj What version of Firefox are you using? Can you try reproducing the problem on jsFiddle? Commented Nov 9, 2011 at 16:28
  • You've written "disabled" wrong. You can reproduce the problem with this one: jsfiddle.net/zMnDj/2 I'm using Firefox 7. Commented Nov 9, 2011 at 23:54

1 Answer 1

2

Try the following:

document.getElementById('button1').removeAttribute('disabled');
document.getElementById('button1').click();

Update

Using jQuery, a cross browser solution would be:

var element = $('#button1');
element.removeAttr('disabled');
element.click();
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry does not solve the problem look here with Firefox 7: jsfiddle.net/zMnDj/3
@therealmarv I reckon it's a problem with FF7 (works in FF9), are you able to use jQuery? If so this should work cross browser
Thanks this seems the most cleanest solution. I use JQuery BTW: You've forgotten # in code: jsfiddle.net/zMnDj/15 Please edit your answer and then I can confirm it works ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.