简体   繁体   中英

removeAttr(“style”) doesn't work

I have this website: http://thc-cup.ucoz.com/ And to make the login form appear (by pressing the login button) I have to remove the style of the div which is hidden by default and of which I have no control. I used this code:

<script>$("#baseLogForm").removeAttr("style");</script>

But it is not working, the div from where it should remove the style is still there.

Why it isn't working? Thanks

Your code isn't working because when it runs, your DOM isn't ready.

Try this way:

$(document).ready(function(){
  $("#baseLogForm").removeAttr("style");
});

or the shorter way...

$(function(){ //<< This is a "shortcut" to $(document).ready()
  $("#baseLogForm").removeAttr("style");
});

BUT... You could simply do a .show() on this form, this will remove the display: none property in the style attribute of your form.

You should simply use .show()

  $(document).ready(function(){
      $("#baseLogForm").show();
  });

Note : If you remove style attribute, if there are other css style those will be removed too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM