I was under the assumption that if I disabled a div, all content got disabled too.
However, the content is grayed but I can still interact with it.
Is there a way to do that? (disable a div and get all content disabled also)
I was under the assumption that if I disabled a div, all content got disabled too.
However, the content is grayed but I can still interact with it.
Is there a way to do that? (disable a div and get all content disabled also)
Below is a more comprehensive solution to masking divs enabling
Also included is hourglassOn and hourglassOff which can be used separately
With this you can do for example:
see jsfiddle
EDIT: Below I've used
.on()
method, instead use.bind()
methodto remove your setting, you can use
.unbind()
method. Whereas the.off()
method doesn't work as expected.After researching hundreds of solutions! learning about pointer-events, below is what I did.
As @Kokodoko mentioned in his solution which is apt for all browsers except IE.
pointer-events
work in IE11 and not in the lower versions. I also noticed in IE11, pointer-events do not work on the child elements. And hence if we have something like belowwhere span -is the child element, setting
pointer-events: none
wont workTo overcome this problem I wrote a function which could act as pointer-events for IE and will work in the lower versions.
In JS File
In CSS File
In HTML
This faked the
pointer-events
scenario wherepointer-events
doesnt work and when the above condition of child elements occur.JS Fiddle for the same
How to disable the contents of a DIV
The CSS
pointer-events
property alone doesn't disable child elements from scrolling, and it's not supported by IE10 and under for DIV elements (only for SVG). http://caniuse.com/#feat=pointer-eventsTo disable the contents of a DIV on all browsers.
Javascript:
Css:
To disable the contents of a DIV on all browsers, except IE10 and under.
Javascript:
Css:
Use a framework like JQuery to do things like:
Disable And Enable Input Elements In A Div Block Using jQuery should help you!
As of jQuery 1.6, you should use
.prop
instead of.attr
for disabling.Here is a quick comment for people who don't need a div but just a blockelement. In HTML5
<fieldset disabled="disabled"></fieldset>
got the disabled attribute. Every form element in a disabled fieldset is disabled.Another way, in jQuery, would be to get the inner height, inner width and positioning of the containing DIV, and simply overlay another DIV, transparent, over the top the same size. This will work on all elements inside that container, instead of only the inputs.
Remember though, with JS disabled, you'll still be able to use the DIVs inputs/content. The same goes with the above answers too.