Hide/Remove Div: Difference between revisions
From D3xt3r01.tk
Jump to navigationJump to search
New page: ==Remove DIV Source== <source lang="javascript"> <script type="text/javascript"> function removeEvent(divNum){ var d = document.getElementById('myDiv'); var olddiv = docum... |
mNo edit summary |
(No difference)
|
Latest revision as of 11:36, 26 January 2012
Remove DIV Source
<script type="text/javascript">
function removeEvent(divNum){
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
return false;
}
</script>
Info about removing div
Just wrap your whole content into a div with id myDiv .. then use removeEvent(id); id being the id of the div you want to remove from within myDiv. What this does is simply store myDiv in a var, the id you want to remove in another var .. and remove one from the other ! Simple as that !
Remove div Example
<html>
<head>
<script type="text/javascript">
function removeEvent(divNum){
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
return false;
}
</script>
</head>
<body>
<div id="myDiv">
<div id="removable">
<a href="#" onclick="removeEvent('removable');">REMOVE ME</a>
</div>
</div>
</body>
</html>
Hide DIV Source
<script type="text/javascript">
function hideDiv(divid){
if(document.getElementById) {
document.getElementById(divid).style.visibility = 'hidden';
}else{
if(document.layers){
document.divid.visibility = 'hidden';
}else{
document.all.divid.style.visibility = 'hidden';
}
}
}
function showDiv(divid){
if(document.getElementById){
document.getElementById(divid).style.visibility = 'visible';
}else{
if (document.layers){
document.divid.visibility = 'visible';
}else{
document.all.divid.style.visibility = 'visible';
}
}
}
</script>
Info about hide/show div
It just sets the visibility of a div... getting the id as a parameter ..
hide/show div example
<html>
<head>
<script type="text/javascript">
function hideDiv(divid){
if(document.getElementById) {
document.getElementById(divid).style.visibility = 'hidden';
}else{
if(document.layers){
document.divid.visibility = 'hidden';
}else{
document.all.divid.style.visibility = 'hidden';
}
}
}
function showDiv(divid){
if(document.getElementById){
document.getElementById(divid).style.visibility = 'visible';
}else{
if (document.layers){
document.divid.visibility = 'visible';
}else{
document.all.divid.style.visibility = 'visible';
}
}
}
</script>
</head>
<body>
<div id="hideshow">
COME OUT .. COME OUT .. WHEREVER YOU ARE ...
</div>
<a href="#" onclick="hideDiv('hideshow');">HIDE</a>
<a href="#" onclick="showDiv('hideshow');">SHOW</a>
</body>
</html>