This script is for hiding and unhiding an element. An example is
Code:
<html>
<head>
<script type="text/javascript">
function showAlphaDiv()
{
var divid = document.getElementById("mybg");
divid.style.display = "block";
}
function closeAlert()
{
var divid = document.getElementById("mybg");
divid.style.display = "none";
}
</script>
</head>
<body>
<div id="mybg" style="display:none;">HELLO THIS IS SOME TEXT</div>
<input type="button" onclick="showAlphaDiv();" value="Button1" />
<input type="button" onclick="closeAlert();" value="Button2" />
</body>
</html>
When you click on button1, the function showAlphaDiv is run. -
Code:
function showAlphaDiv()
{
var divid = document.getElementById("mybg");
divid.style.display = "block";
}
As the variable mybg has been set to whatever element has the id of mybg
This bit -
Code:
<div id="mybg">HELLO THIS IS SOME TEXT</div>
it sets the style.display to block, which will display the text.
The opossite happens when you click button two.
This function is run -
Code:
function closeAlert()
{
var divid = document.getElementById("mybg");
divid.style.display = "none";
}
which sets the style.display of the element with id mybg to none meaning you can't see it.
NOTES:
Code:
var myAlert = document.getElementById("sendwaiting");
won't do anything as there is no element with the id of sendwaiting.
I made some minor changes to the structure of the script because other-wise it wouldn't have worked (depending on the postion of the script within the page).
Hope this helps
Keyboard1333
Bookmarks