Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery remove attribute

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.

like image 590
Tarek Avatar asked Nov 23 '09 18:11

Tarek


People also ask

How remove data attribute value in jQuery?

jQuery removeAttr() Method The removeAttr() method removes one or more attributes from the selected elements.

How do I remove attributes?

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.

What jQuery method is used to completely remove attributes form elements?

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.

What is remove in jQuery?

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.


1 Answers

All good used this:

$('#WindowOpen').toggle(     function()     {         $('#login_uname, #login_pass').attr("disabled","disabled");          },     function()     {         $('#login_uname, #login_pass').removeAttr("disabled");           }); 
like image 175
Tarek Avatar answered Sep 22 '22 14:09

Tarek