I want to make an onClick event on the link.
the code:
<a onclick="document.getElementById('myBodyID').style.overflow-y='hidden'" title="my title">Anchor text</a>
Why isn't this working? I want to disable vertical scrolling when the link is clicked.
How could I fix this code? It is not working at the moment :(
Use:
document.getElementById('myBodyID').style.overflowY='hidden'
As CSS properties with special characters are camel cased. You can also use brackets ( document.getElementById('myBodyID').style["overflow-y"]
).
You cannot use -
inside such a property literal. Instead, use the []
notation.
.style['overflow-y'] =
Currently, you're fetching .style.overflow
and subtracting y
(as with numbers), which does not make sense here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.