0
Disabled on hover?
I'm trying to make it so a button is only disabled when hovered using JS. Can somebody help me out?
9 Answers
+ 9
try this
in mobile it doesn't work well (no mouse after all)
but i think it should work on a pc
edit: much to my surprise, it worked đ
edit2: onmouseleave instead onmouseout works as well
https://code.sololearn.com/W4Hy3XqmRzGk/?ref=app
+ 6
Daniel Cooper i see....
disabled is not a CSS attribute afaik
+ 4
you can use pointer-events to disbale it
.my-button:hover{
pointer-events:none;
...rest of style...
}
+ 2
Daniel Cooper
if you want to use burey's example in th external js tab
enclose it in he onload event like so: window.onload=function(){
//your script here
}
so the script will run once the whole page is loaded
0
Thanks, but I was trying to set the attribute to disabled using JS. Except every time I try, it doesn't work :(
0
Thanks. Had no idea you could set it like that. I was trying to use setAttribute.
0
It's an HTML attribute.
0
So wait, how come when I type the same code into external JS(AKA the js tab) it doesn't work?
- 1
reminding me that I'm a moron does not make me any less of a moron, now answer the question or don't waste my time. :)