sofian Posted September 23, 2011 Share Posted September 23, 2011 hi i have this code that wen i click on div1 show div2 , wen click again on div1 hide div2 , but wen div2 is show and click on another place on the page it not hide ..... can you please help me to make it wen click on any place on the page hide dive2 too!! <script> $(document).ready(function(){ $("#div1").click(function(e) { e.preventDefault(); if ($("#div2").is(":visible")) { $("#div2").hide(); } else { $("#div2").show(); } }); }); </script> thanks Quote Link to comment https://forums.phpfreaks.com/topic/247695-hide-div-wen-click-on-any-were-on-the-page/ Share on other sites More sharing options...
goodacre.liam Posted September 24, 2011 Share Posted September 24, 2011 Do you mean something like this? jQuery(function ($) { // when clicking on the document $(document).click(function () { // hide/show element '#div2' $('#div2').toggle(); }); }); Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/247695-hide-div-wen-click-on-any-were-on-the-page/#findComment-1272245 Share on other sites More sharing options...
sofian Posted September 24, 2011 Author Share Posted September 24, 2011 Do you mean something like this? jQuery(function ($) { // when clicking on the document $(document).click(function () { // hide/show element '#div2' $('#div2').toggle(); }); }); Hope this helps. thank you very much for your help . but realy i dont want to change the code , i just want to add to the code the option wen click on the page (evry were) hide the div . thank you please not that i dont have any know with php or scripts . Quote Link to comment https://forums.phpfreaks.com/topic/247695-hide-div-wen-click-on-any-were-on-the-page/#findComment-1272313 Share on other sites More sharing options...
goodacre.liam Posted September 24, 2011 Share Posted September 24, 2011 So do you just mean the following? // when clicking on the document $(document).click(function () { // hide element '#div2' $('#div2').hide(); }); Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/247695-hide-div-wen-click-on-any-were-on-the-page/#findComment-1272478 Share on other sites More sharing options...
sofian Posted September 25, 2011 Author Share Posted September 25, 2011 So do you just mean the following? // when clicking on the document $(document).click(function () { // hide element '#div2' $('#div2').hide(); }); Hope this helps. thank you man very much . wen i add your code the script stop to work . sorry ... please forget from this . i will stay as it as . thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/247695-hide-div-wen-click-on-any-were-on-the-page/#findComment-1272558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.