Today I am going to demonstrate here, how can we hide or show div with pure JavaScript?.
Here is step by step procedure:
1) CREATE A HTML FILE FOR BROWSER VIEW AND SAVE IT AS INDEX.HTML
<!doctype html>
<
html
>
<
head
>
<
title
>Show and hide div with JavaScript</
title
>
<
script
src
=
"show.js"
></
script
>
</
head
>
<
body
>
<
div
id
=
"newpost"
>
This div will be show and hide on button click</
div
>
<
button
id
=
"button"
onclick
=
"showhide()"
>Click Me</
button
>
</
body
>
</
html
>
2) CREATE A JAVASCRIPT FILE FOR SHOW AND HIDE DIV AND SAVE IT WITH SHOW.JS
function
showhide()
{
var div = document.getElementById('newpost');
if (div.style.display !== "
none
") {
div.style.display = "
none
";
}
else {
div.style.display = "
block";
}
}
Thats all done, now you can show and hide your div on button click.
Hope it will help someone, somewhere. Please Contact me for any assistance.
Recent Comments