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
2 Answers
Reset to default 8You 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();