简体   繁体   中英

Javascript: show/hide HTML node

I have an HTML page with some paragraphs which I would like to show or hide via Javascript. What should I do? Do I have to use the display property in the CSS file too? Thank you

EDIT: Since the paragraphs will be the error messages of a form, I'd like that at the beginning none of them were visibile.

You can do like this :

To hide :

document.getElementById("elementId").style.display = 'none';

To show:

document.getElementById("elementId").style.display = 'block';

To hide initially do this and better you put them in span not para

 $(document).ready( function() {
     $("span").hide();
 });

And whenever you need them to show call a javascript function on submit button and show using same

$("span").show();

But do not do like this this will show all messages, Put your if else logic and than show them by Id or class using jquery

$("#id").show();
$(".class").show();

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