I am using javascript and I need to change the style: pointer-events:none to pointer-events:auto and vice versa. How can I do this?
2 Answers
I have a function that swaps the pointer event on an element.
in JavaScript
function swapPE(forme){
if (forme.style.pointerEvents == "none") forme.style.pointerEvents = "auto";
else forme.style.pointerEvents = "none";
};
I usually activate this function by attaching the eventhandler
onClick(swapPE(this);)
to the element if directly activated. If not I just call it with a reference to the element ID.
Previous to this I often wanted to change some appearance of the element as well so I used JavaScript to change the classname of the element where each classname included the relevant pointer-event statement.
If you want to use more then one pairing of pointer-events just send parameters.
onClick(swapPE(this, "auto", "none");)
or
onClick(swapPE(this, "all", "none");)
function swapPE(forme, ev1, ev2){
if (forme.style.pointerEvents == ev1) forme.style.pointerEvents = ev2;
else forme.style.pointerEvents = ev1;
};
element.style.pointerEvents = 'auto'should suffice?