Ways to hide controls with JavaScript _javascript tips

Source: Internet
Author: User
Tags visibility
The control is invisible when style.display= "block" or style.visibility= "visible", when style.display = "None" or style.visibility = "hidden".
The difference is that "display" not only hides the control, but the hidden control no longer occupies the position used by the display, while the "visibility" hidden control simply sets the control to invisible, and the control still occupies its original position.
<p>
<input id= ' control ' value= "controls you want to hide" >
</p>
<p>
Hides the above control and makes it not occupy the position on the page
<input type= "button" value= ' Hide ' onclick= ' Displayhide_control () ' >
<input type= "button" value= ' Show ' onclick= ' Displayshow_control () ' >
<br/>
Only hides the control, its position still occupies
<input type= "button" value= ' Hide ' onclick= ' Visibilityhide_control () ' >
<input type= "button" value= ' Show ' onclick= ' Visibilityshow_control () ' >
</p>
<script language= "javascript" type= "Text/javascript" >
function Displayhide_control ()
{
var _control = document.getElementById ("control");
_control.style.display= "None";
}
function Displayshow_control ()
{
var _control = document.getElementById ("control");
_control.style.display= "Block";
}
function Visibilityhide_control ()
{
var _control = document.getElementById ("control");
_control.style.visibility= "hidden";
}
function Visibilityshow_control ()
{
var _control = document.getElementById ("control");
_control.style.visibility= "visible";
}
</script>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.