Guilherme Longo
Guilherme Longo

Reputation: 2308

$(document).click(): does not fire alerts

Might be simple but I can find a reasonable explanation for that

$(document).ready(function(){
    $(document).click(function () {
        alert('ok');
    });
});

Does not fire the alert(); I am using the newest google chrome. Does browser put some restriction for that as there is in ajax callback functions?

Edit 1: Code is within $(document).ready();

Upvotes: 0

Views: 139

Answers (3)

Aarif Qureshi
Aarif Qureshi

Reputation: 474

try

$().ready(function() {   
    alert('ok');
});

Upvotes: -1

Pranav Singh
Pranav Singh

Reputation: 20111

Strange but true, that's working on firefox but not on chrome. Try this one, works for me for latest version of chrome and firefox too:

$(document.body).click(function () {
     alert('ok');
});

Upvotes: 1

Mr_Green
Mr_Green

Reputation: 41832

I think you forgot to Encapsulate your code with

$(function(){
   //your code here 
});

or

$(document).ready(function(){
    //your code here
});

Upvotes: 3

Related Questions