简体   繁体   中英

Hidding or deleting text nodes

I need to hide all form's content and replace it ( .find('*').each() {$(this).hide} doesn't work) I have problem hiding text nodes :

      <form onsubmit="javascript:... ">
  <!--text node -->  bad&nbsp;
      <input type="radio" name="imgvote" value="1" style="display: none;">

I'm guessing that you're using $("form").children().hide() which won't hide the text nodes, only elements. Instead you want:

$("form").contents().hide();

But hiding is different to replacing. To completely replace everything inside the form, you can either do:

$("form").html("blah blah <input type='text'>");

Or empty it first, and then append elements:

$("form").empty().append("blah blah <input type='text'>");

Yet another alternative, is to make sure all your text is wrapped nicely in an element (most of the time this is more semantically correct) for example, "bad" should probably be inside a <p> or a <label>

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