Use the CSS property pointer-events
for an element to disable user interaction with it and its descendants.
div.disabled { pointer-events: none; }
You can also use the property user-select
to further limit the interaction of text with text.
div.disabled { user-select: none; }
Note that the property user-select
may require vendor prefixes.
However, these CSS properties will not disable keyboard interaction, which can occur by tabbing in descendants.
- https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees; inert
, .
, Javascript . keydown
capture
returnValue
false
. Tab , .
var noInteracts = document.getElementsByClassName('disabled');
[].map.call(noInteracts, function(elem) {
elem.addEventListener("keydown", function(e) {
if (e.keyCode != 9) {
e.returnValue = false;
return false;
}
}, true);
});
CSS:
div.disabled *:focus { outline: 0; }
.
-: http://jsfiddle.net/abhitalks/hpowhh5c/5/
var noInteracts = document.getElementsByClassName('disabled');
[].map.call(noInteracts, function(elem) {
elem.addEventListener("keydown", function(e) {
if (e.keyCode != 9) {
e.returnValue = false;
return false;
}
}, true);
});
div.disabled {
pointer-events: none;
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none;
user-select: none;
}
div.disabled *:focus { outline: 0; }
<p>This is normal</p>
<form>
<label>Input 1: <input id="i1" /> </label>
<button>Submit</button>
</form>
<hr />
<div class="disabled">
<p>User interaction is disbled here</p>
<form>
<label>Input 2: <input id="i2" /> </label>
<button>Submit</button>
</form>
<p>Lorem ipsum</p>
</div>
Hide result