JS DOM programs collection
JS program to show and hide the content using getElementById (DOM)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>hiding and showing the text(toggling)</title>
</head>
<body>
<p id="para1">this is JS code</p>
<button onclick="shText();">click to hide/show</button>
<script>
function shText()
{
var p;
p=document.getElementById('para1');
if(p.style.display=="none")
{
p.style.display="block";
}
else
{
p.style.display="none";
}
}
</script>
</body>
</html>
Output:
![]() |
JS program to hide/show the contents |
