I like to add one that also works with dynamically creating Davascript DOM, like D3, where it is impossible to add:
//.attr(function(){if(condition){"readonly"]else{""}) //INCORRECT CODE !
to prevent actions on the DOM input element in HTML add readonly to the class:
var d = document.getElementById("div1"); d.className += " readonly";
OR in D3:
.classed("readonly", function(){ if(condition){return true}else{return false} })
And add to CSS or less:
.readonly { pointer-events: none; }
The best part about this solution is that you can dynamically turn it on and off in functions so that it can be integrated, for example, into D3 during creation (impossible with a single attribute "readonly").
to remove an item from a class:
document.getElementById("MyID").className = document.getElementById("MyID").className.replace(/\breadonly\b/,'');
or use jquery:
$( "div" ).removeClass( "readonly" )
or switch class:
$( "div" ).toggleClass( "readonly", addOrRemove );
Just to be complete, good luck = ^)
irJvV Feb 26 '16 at 9:23 2016-02-26 09:23
source share