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?

5th Jun 2018, 4:22 AM
Daniel Cooper
Daniel Cooper - avatar
10 Respuestas
+ 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
5th Jun 2018, 6:25 AM
Burey
Burey - avatar
+ 6
Daniel Cooper i see.... disabled is not a CSS attribute afaik
5th Jun 2018, 7:00 AM
Burey
Burey - avatar
+ 4
you can use pointer-events to disbale it .my-button:hover{ pointer-events:none; ...rest of style... }
5th Jun 2018, 5:46 AM
Burey
Burey - avatar
+ 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
5th Jun 2018, 11:19 AM
seamiki
seamiki - avatar
0
Thanks, but I was trying to set the attribute to disabled using JS. Except every time I try, it doesn't work :(
5th Jun 2018, 5:56 AM
Daniel Cooper
Daniel Cooper - avatar
0
Thanks. Had no idea you could set it like that. I was trying to use setAttribute.
5th Jun 2018, 6:49 AM
Daniel Cooper
Daniel Cooper - avatar
0
It's an HTML attribute.
5th Jun 2018, 7:00 AM
Daniel Cooper
Daniel Cooper - avatar
0
So wait, how come when I type the same code into external JS(AKA the js tab) it doesn't work?
5th Jun 2018, 8:05 AM
Daniel Cooper
Daniel Cooper - avatar
- 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. :)
5th Jun 2018, 4:40 AM
Daniel Cooper
Daniel Cooper - avatar