Jump to content

hide div wen click on any were on the page


sofian

Recommended Posts

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

Link to comment
Share on other sites

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 .

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.