How can I remove an attribute with jQuery

0 votes

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.

Jun 2, 2022 in JQuery by Edureka
• 13,670 points
8,698 views

1 answer to this question.

0 votes

The removeAttr() method is an inbuilt method in jQuery which is used to remove one or more attributes from the selected elements. Parameters: This function accepts single parameter attribute which is mandatory. It is used to specify one or more attributes to remove.

answered Jun 2, 2022 by Edureka
• 13,670 points

Related Questions In JQuery

0 votes
1 answer

How can I select an element with multiple classes in jQuery?

Hello @kartik, If you want to match only ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,880 points
2,991 views
0 votes
1 answer

How can I refresh a page with jQuery?

Hello @kartik, Use location.reload(): $('#something').click(function() { location.reload(); }); The reload() function ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,880 points
1,716 views
0 votes
1 answer

How can I refresh a page with jQuery?

Use the JavaScript location. reload() Method You can simply ...READ MORE

answered Jun 10, 2022 in JQuery by gaurav
• 23,260 points
648 views
0 votes
0 answers

How can I upload files asynchronously with jQuery?

I would like to upload a file ...READ MORE

Jun 10, 2022 in JQuery by gaurav
• 23,260 points
495 views
0 votes
1 answer

How can I implement my own $(document).ready functionality without using jQuery?

Hello @kartik,  There are three options: If script is the last ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
1,328 views
0 votes
1 answer

How do I pre-populate a jQuery Datepicker textbox with today's date?

Hello @kartik, You must FIRST call datepicker() > then use ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,880 points
11,494 views
0 votes
1 answer

How to move an item programmatically with jQuery sortable while still triggering events?

Hello, $("selector").trigger("sortupdate"); you will have to  pass as second argument  ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,880 points
3,745 views
0 votes
1 answer

How do I check if the mouse is over an element in jQuery?

Hello @kartik, Use this code: $("someelement").mouseenter(function(){ ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,880 points
2,053 views
0 votes
1 answer

How can I Validate forms with jquery?

Then to define rules use simple syntax. ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,670 points
280 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP