Reputation: 1979
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.
Upvotes: 1
Views: 18369
Reputation: 147
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();
Upvotes: -2
Reputation: 325
You can do like this :
To hide :
document.getElementById("elementId").style.display = 'none';
To show:
document.getElementById("elementId").style.display = 'block';
Upvotes: 8