Rajeev Ranjan Sharma
Rajeev Ranjan Sharma

Reputation: 215

How to hide div

I need some script.

  1. To hide a div by clicking anywhere on the page
  2. To hide a div by clicking on button, images or particular script
  3. To hide a div by clicking anywhere on the page ( when div contain any other script)

I am currently using

<script>
    $(document).ready(function () {

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

            document.getElementById('div').style.display = 'none';

      });

    });
    </script>

This working fine why div contain images, but it not working when div contain script like advertisement script such as chitika, adsense or any other

Please tell how to do.

Upvotes: 0

Views: 143

Answers (3)

Eda190
Eda190

Reputation: 679

This code answers to your first and third question:

$( document.body ).click(function() {
document.getElementById(name of your div).style.display = 'none';
});

And the second question:

<div id="testdiv">test</div>
<script>
    function hidediv(){
    document.getElementById("testdiv").style.display = 'none';
    }
</script>
<input type=button value="Click me" onclick="hidediv()">  

Upvotes: 0

HEEN
HEEN

Reputation: 4721

To hide it, you would do some javascript and

Also you need to include Jquery library

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
$("#YourDivID").click(function (){     //inspect the ID might differ.
      $(this).hide();
  });

Upvotes: 0

I&#39;m Geeker
I&#39;m Geeker

Reputation: 4637

Try this use this this selector is used to hide the clicked div

$("#div").click(function () {
          $(this).hide();
      });

Upvotes: 1

Related Questions