Possible Duplicate:
dynamically add/remove style in javascript
It's required to write javascript functions to disable and enable selection of the element. I wrote sample code:
<style type="text/css">
.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
.selectable {
-moz-user-select: text;
-khtml-user-select: text;
-webkit-user-select: text;
user-select: text;
}
</style>
<script>
function makeUnselectable(node) {
if (node.nodeType == 1) {
node.unselectable = true;
}
var child = node.firstChild;
while (child) {
makeUnselectable(child);
child = child.nextSibling;
}
}
function makeSelectable(node) {
if (node.nodeType == 1) {
node.unselectable = false;
}
var child = node.firstChild;
while (child) {
makeSelectable(child);
child = child.nextSibling;
}
}
</script>
But this code is incorrect and doesn't work. How to add and remove style component on the fly by javascript? All the current element's styles and the class should remain!