JS Control div Display hidden

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax block code content control display document examples

This article provides two on the JS control div display hidden code, using the Js+div ID to control the specified div is shown or hidden, let's look at two examples of this problem, the method is very simple.

<html>
<head>
<meta http-equiv= "Content-type" content= "html; charset=gb2312"/>
<title>js Control div display hidden </title>
<script language= "Web Effects" type= "Text/javascript"
<!--
Function Toggle (targetid) {
    if (document.getElementById) {
         Target=document.getelementbyid (Targetid);
            if (target.style.display== "block") {
                Target.style.display = "None";
           } else {
                 target.style.display= "Block";
           }
   }
}

</script>
<style type= "Text/css
<!--
#div1 {
Background-color: #000000;
height:400px
width:400px;
Display:none;
}
;
</style>
</head>

<body>
<input type= "button" id= "Butn" value= "Show/Hide" onclick= "toggle (' Div1 ')"/>
<center>
<div id= "Div1" ></div></center>
Centered Div
</body>
</html>

Method Two

<html>
<head>
<title> Show and hide </title>
<script>
function dis (b) {
document.getElementById (' QQ '). Style.display = (document.getElementById (' QQ '). style.display== "Block")? "None": "Block";
B.value = (b.value== "display")? "Hide": "Show";
}
</script>
<style type= "Text/css"
#qq {display:none}
</style>
</head
<body>
<input type= "button" name= "Submit" value= "display" onclick= "dis (this)"
<div id= "QQ"
<table width= "height="   border= "0" cellpadding= "1" cellspacing= "1"
  <tr>
    <td width= "100%" bgcolor= "#3366ff" > content, this table is nested in the ID &quot;qq&quot; div </td
  </TR>
</table>
</div>
</body>
</html>

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.