最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript: showhide HTML node - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Dec 7, 2013 at 11:53 user3067088user3067088 1,9874 gold badges17 silver badges20 bronze badges 2
  • it depends on when you want to hide them ... – Kristof Feys Commented Dec 7, 2013 at 11:55
  • provide some code what you tried so far – Rahil Wazir Commented Dec 7, 2013 at 11:55
Add a ment  | 

2 Answers 2

Reset to default 8

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();
发布评论

评论列表(0)

  1. 暂无评论