开发者

HTML DOM remove label

I have a label like

<label for="Some Feild" >Some Text </label>

Now I want to set the style of display of this label to none开发者_高级运维

How can I do this ?


Give it an id, then do:

document.getElementById(myLabelId).style.display = "none";

Or, if you didn't mean "by javascript" :

<label for="Some Feild" style="display:none" >Some Text </label>


give id to the label tag as <label for="Some Feild" id="someLabel" >Some Text </label> and then document.getElementById(myLabelId).removeChild(); would remove inner content of that label.


You can do this many ways. Here are 5 ways Id do it, and 2 methods using jQuery are included.

  1. $('[for="Some Feild"]').css('display','none');
  2. $('[for="Some Feild"]').fadeOut();
  3. document.getElementById(myID).style.display = "none";
  4. [for="Some Feild"] {display:none}
  5. Some Text

All of the above will hide the span.

  1. This is the jQuery method of changing the CSS
  2. This way jQuery will fade out your span for a nice effect.
  3. This is the raw JS method, however, you need to add an ID to your label for it to work
  4. This is the CSS to change it in tags or in an external style sheet.
  5. This is the quick and dirty way of doing it with CSS.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜