jQuery .prop("disabled", false) not working in Chrome
Asked Answered
L

5

19

having problems with .prop("disabled", false) it's works fine in opera and firefox but IE and chrome i can't get it to work..

Actualy it's a invination form and im make send button like this

<input id="sendInvite" class="mail_send" disabled="disabled" type="button" name="invite" value="Send">

and here is css

.mail_send[disabled="disabled"] {background-color:#343434; color:#747474}

So as you can see button is disabled and you can't click, you must first write your name and mail after that button is remove disabled and you can send mail. For this im write code here is: http://pastebin.com/8u23G90b

But something is wrong here, in chrome and IE disabled never removed from button, im also load jquery 1.7.1

p.s sorry for my english

Larrylars answered 11/2, 2012 at 13:5 Comment(1)
Fiddle link is brokenLabored
W
23

Remove the attribute:

$('button').removeAttr("disabled");

See .removeAttr() for more details

Willwilla answered 11/2, 2012 at 13:27 Comment(2)
I just tried both method in chrome 17, and they both work. I think your problem may lie else where, are you getting any errors on the console?Willwilla
interesting.. works also for me on chrome 16 on jsfiddle, on site don't work..there is no error in console. hmm..Larrylars
M
2

Your problem is not with JQuery, but with your CSS selectors. The disabled attribute is referring to the default value when the page first loads, rather than whether the element is actually disabled or not.

The CSS selector you want is the :disabled selector:

.mail_send:disabled {background-color:#343434; color:#747474}

You can see an example with this jsfiddle.

Mellins answered 24/7, 2013 at 22:52 Comment(0)
C
0

Try to write it like that:

$('myButton').prop("disabled", "");
Cheffetz answered 11/2, 2012 at 13:11 Comment(0)
C
0

just use button and live:

<button class="sendm">Send Email</button>

$(".sendm").live("click", function(e){
   var field1 = $("").val();
   var field2 = $("").val();

   if(field1 === "" || field2 === "" ){
    /// fake checker, you make this more robust etc
     return false;  // maybe do an alert here
   } else {
      //post form data and get json response
   }

});

 $(document).ready(function(){ $(".sendm").button(); });
Caltrop answered 11/2, 2012 at 13:14 Comment(0)
C
0

I was running into a similar issue where I was using .prop("disabled", false) to remove disabled from a 'Save' button. Disabled was being assigned via .prop("disabled", true).

But wait who what - when trying to remove this property (which would be rendered as disabled in the html tag) I discovered that it was being output as class="disabled"!

For this - i used .removeClass('disabled') All i'm trying to say is if things don't work the way you think they should, make sure their initial output is what you'd expect.


Counteroffensive answered 5/12, 2014 at 0:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.