Changing CSS “z-index” property: “Invalid left-hand side in assignment”

后端 未结 2 1022

I have an element with the onmouseover event handler which calls a function I made that is suppose to change the css property of another element and I gave that element the ID \

相关标签:
2条回答
  • 2021-01-24 11:39

    Style names in Javascript use camelCase, so it should be:

    document.getElementById("output").style.zIndex="-1";
    

    - is the arithmetic subtraction operator, it can't used in identifiers.

    0 讨论(0)
  • 2021-01-24 12:00

    You forgot a quote, and hyphens aren't allowed in property names, so usually camelcase is used instead

    <script>
    function ChangeZofO () {
        document.getElementById("output").style.zIndex = -1;
    }
    </script>
    
    <div id="MyDiv" onmouseover="ChangeZofO()"></div>
    
    0 讨论(0)
提交回复
热议问题