jQuery $('html, body').not()

click, jquery

Solution

You can use the event argument to see what target was clicked and return false

$("html, body").click(function(e) {
    if ($(e.target).hasClass('entry-content')) {
        return false;
    }
    alert('d');
});​

http://jsfiddle.net/keyZw/

You are using the .not() filter.. but it's still part of your html/body.. so you need to handle it inside the click function. Also you are just binding the click event..

So

 // find html,body - not ones with class=entry-content - bind click
 $("html, body").not('.entry-content')

So that doesn't prevent the alert as your div is still inside the body

As mentioned.. you only need to bind to the body really

$("body").click(function(e) {
    if ($(e.target).hasClass('entry-content')) {
        return false;
    }
    alert('d');
});​

Problem

here - I want alert to happen when you click anywhere but not on the div. When I click on div, alerts shows too. JS ``` $("html, body").not('.entry-content').click(function() { alert('d'); }); ​ ``` HTML ``` <div class="entry-content"> kkkk </div>​ ```

Original source