Hi i have a div of a form. i want that disable click event when mouse is out of the div. So i tried this but it is not working ot of div is still clickable. Any idea??
var flag = false;
$("#foo").live("mouseenter",function(){
flag = true;
}).live("mouseleave",function(){
flag = false;
})
$(document).click(function(){
if(!flag)
return false;
});
You can create a div with fixed position that spans the entire screen and place what you want to be able to click inside of it, making all the clicks outside that element actually be on that "empty" div. I also had to add z-index:10000 to deal with some unruly underlying components.
To disable a link using CSS, pointer-events property can be used, which sets whether the element in the page has to respond or not while clicking on elements. The pointer-events property is used to specify whether element show to pointer events and whether not show on the pointer.
To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element.
You cannot prevent the click event being fired from the whole document. You can do it per element basis. You can probably block the whole screen using a absolute positioned transparent(low opacity) div and hide it again once the div is visible.
var $body = $(document.body);
var $div = $("<div id='dummyDiv'/>").hide().appendTo($body);
$div.css({position:"absolute", height: $body.height(), width: $body.width(), background: "#000", opacity: 0.5}).show(100);
//to hide it
$("#dummyDiv").hide(100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With