Js implements div click hiding and code display

Source: Internet
Author: User

Js code

Code directly:

The code is as follows: Copy code

<Script type = "text/javascript">
Function showorhiddenme (){
Var t_div = document. getElementById ("test ");
If (t_div.style.display = "block "){
T_div.style.display = "none ";
} Else if (t_div.style.display = "none "){
T_div.style.display = "block"
        }
    }
</Script>

Let's look at the jquery example.

The code is as follows: Copy code

<Script type = "text/javascript">
$ (Function (){
Alert((('{a'}.css ('display '));
Alert((('% B '%.css ('display '))
})
</Script>

<Div id = "a"> a </div>
<Div id = "B" style = "display: none"> B </div>

Of course, jquery toggle is the easiest way to hide div display.

The code is as follows: Copy code

<Html>
<Head>
<Script type = "text/javascript" src = "/jquery. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ (". Btn1"). click (function (){
$ ("P"). toggle (1000 );
});
});
</Script>
</Head>
<Body>
<P> This is a paragraph. </p>
<Button class = "btn1"> Toggle </button>
</Body>
</Html>

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.