5

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?

4
  • I normally supply much more info, but I think this is simply a question with a very basic subject and answer Commented Sep 19, 2013 at 21:52
  • 1
    Which bit are you having difficulty with? element.style.pointerEvents = 'auto' should suffice? Commented Sep 19, 2013 at 21:55
  • Ah that was my problem, I did not know the javascript property for pointer-events. I could have used z-index as well, but that would have been more of a hack Commented Sep 19, 2013 at 21:58
  • 1
    generally if the css property has a hyphen, the js equivalent is camelCase Commented Sep 19, 2013 at 22:16

2 Answers 2

5

With jQuery you can use:

$(function(){
    $('#yourElement').css('pointer-events', 'auto');
});
Sign up to request clarification or add additional context in comments.

Comments

0

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;
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.