简体   繁体   中英

Hiding a DIV by click on another DIV

I have a 'div' tag( by id=go) and write a script which i click on div, then another div (by id=example) will be shown, and show some data: this is my div :

  <div id="go" style="position: relative">Click</div>
  <div id="example" style="position: relative"></div>

and the script:

 $("#go").click(function () {

                   $("#example").fadeIn(1200);
                   $("#count").text('');
                    setInterval(
                         function () {
                            p(); count();
                          }, 8000);
                    });

and i want when i click on div(by id= go) agin the div (with id=example) be hide , How can i improve my script to do it?

You can use fadeToggle() to toggle between fadeIn() and fadeOut() here:

$("#example").fadeToggle(1200);

Fiddle Demo

Did you try .toggle() ? Reference is at jQuery docs . AFAIK it does all you need - including animation.

Use .toggle() . Check this

$("#example").hide();
$("#go").click(function () {
      $("#example").toggle('slow');
});

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM