I can't seem to get removeAttr
to work, I'm using the example I saw on the jQuery site. Basically onclick
I add the attribute to disable a field (which works just fine) but when the user clicks again it should enable the field in question. I used alerts to make sure the else block is being fired, so I know that's not it.
Code:
$('#WindowOpen').click(function (event) { event.preventDefault(); $('#forgot_pw').slideToggle(600); if('#forgot_pw') { $('#login_uname, #login_pass').attr('disabled','disabled'); } else { $('#login_uname, #login_pass').removeAttr('disabled'); } });
Thanks.
jQuery removeAttr() Method The removeAttr() method removes one or more attributes from the selected elements.
The removeAttribute() method removes an attribute, and does not have a return value. The removeAttributeNode() method removes an Attr object, and returns the removed object.
remove() method takes elements out of the DOM. Use . remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.
jQuery remove() Method The remove() method removes the selected elements, including all text and child nodes. This method also removes data and events of the selected elements. Tip: To remove the elements without removing data and events, use the detach() method instead.
All good used this:
$('#WindowOpen').toggle( function() { $('#login_uname, #login_pass').attr("disabled","disabled"); }, function() { $('#login_uname, #login_pass').removeAttr("disabled"); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With