JavaScript setting pointer-events

前端 未结 3 875
半阙折子戏
半阙折子戏 2021-02-03 17:05

I am trying to set pointer-events: none for a div through JavaScript, however the property is not being applied.

I have tried:

document.getE         


        
相关标签:
3条回答
  • 2021-02-03 17:42

    There is an example in a book which uses element.setAttributeNS(null, "pointer-events", "none"); instead of using element.style.pointer-events = "none";.

    0 讨论(0)
  • 2021-02-03 17:49

    You can access style properties via Bracket notation like this:

    document.getElementById("div").style['pointer-events'] = 'auto';
    

    No need in camel case modification in this case.

    0 讨论(0)
  • 2021-02-03 18:01

    Your first attempt failed because it was a CSS property and not an attribute (part of the style attribute).

    Your second attempt failed because for some off reason, when making this API casing-like-this gets converted to camelCasingLikeThis . This is likely because the folks who built JavaScript and the folks who built CSS weren't very well coordinated.

    The following should work:

    document.getElementById("div").style.pointerEvents = "none";
    
    0 讨论(0)
提交回复
热议问题