I am willing to create div’s dynamically on double clicking anywhere on the page. Can I apply click event to body element?
Here’s what I tried so far:
jQuery("document").ready(function(){
alert("click");
jQuery("body").dblclick(function(event){
alert("click");
});
});
Yes:
Is there something you tried that didn’t work?
Responding to your comment,
The problem is you’re using a tag selector to look for the document object.
jQuery("document")will look for an element in the document called<document>, which doesn’t exist. You need to just pass in the document object, so:Also, by default a
<body>element is only as big as its content, so if you apply thedblclickevent to a<body>with no content, only the top-left part of the document will fire the event. Instead, you want to apply it to thedocumentobject instead: