Updating z-index with javascript invalid left-hand side in assignment

前端 未结 1 1352
说谎
说谎 2021-01-21 09:03

I\'m having a problem with Javascript. It\'s almost certainly something I\'m doing wrong as I\'m quite new to js. I\'m trying to modify a div tag\'s z-index to 1 from -1 so an i

1条回答
  •  无人及你
    2021-01-21 09:39

    When addressing CSS properties in javascript, anything that has a hyphen is transformed to camel case. Try this instead:

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

    Related Q/A

    Edit: Additional information for posterity, as said by khanahk in a comment, a hyphen in a variable name will be interpreted as a minus sign, and this is not valid assignment syntax. An interesting and not recommended way around this is to use bracket notation instead:

    document.getElementById("img-bubble1").style["z-index"] = "1";
    

    0 讨论(0)
提交回复
热议问题