The task is to remove the CSS:hover property from the element. Here we are going to use JavaScript to solve the problem.
Approach 1:
- Simply remove the class which is adding the hover effect to the element using JQuery by .removeClass() method.
Example 1: This example using the approach discussed above.
<!DOCTYPE HTML> <html> <head> <title> How to Disable a CSS :hover effect. </title> <script src= </script> <style> .element { height: 100px; width: 200px; background: green; color: white; margin: 0 auto; } .hover:hover { background: blue; } </style> </head> <body style = "text-align:center;" id = "body"> <h1 id = "h1" style = "color:green;" > GeeksForGeeks </h1> <p id = "GFG_UP" style = "font-size: 15px; font-weight: bold;"> </p> <div id = "div" class = "element hover"> Hover It </div> <br> <button onclick = "gfg_Run()"> Click here </button> <p id = "GFG_DOWN" style = "font-size: 23px; font-weight: bold; color: green; "> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var heading = document.getElementById("h1"); var div = document.getElementById("div"); el_up.innerHTML = "Click on the button to remove the CSS:hover effect."; function gfg_Run() { $('#div').removeClass('hover'); el_down.innerHTML = "Hover effect Removed"; } </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before clicking on the button:
-
On hovering over the element:
-
After clicking on the button:
Approach 2:
- Simply remove the class which is adding the hover effect to the element using JavaScript by .classList.remove() method.
Example 2: This example using the approach discussed above.
<!DOCTYPE HTML> <html> <head> <title> How to Disable a CSS :hover effect. </title> <style> .element { height: 100px; width: 200px; background: green; color: white; margin: 0 auto; } .hover:hover { background: blue; } </style> </head> <body style = "text-align:center;" id = "body"> <h1 id = "h1" style = "color:green;" > GeeksForGeeks </h1> <p id = "GFG_UP" style = "font-size: 15px; font-weight: bold;"> </p> <div id = "div" class = "element hover"> Hover It </div> <br> <button onclick = "gfg_Run()"> Click here </button> <p id = "GFG_DOWN" style = "font-size: 23px; font-weight: bold; color: green; "> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var heading = document.getElementById("h1"); var div = document.getElementById("div"); el_up.innerHTML = "Click on the button to remove the CSS:hover effect."; function gfg_Run() { document.getElementById('div').classList.remove("hover"); el_down.innerHTML = "Hover effect Removed"; } </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before clicking on the button:
-
On hovering over the element:
-
After clicking on the button:
Recommended Posts:
- How to create Skewed Background with hover effect using HTML and CSS?
- How to create paper corner fold effect on hover by using HTML and CSS?
- How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ?
- How to disable text selection highlighting using CSS?
- How to disable a link using only CSS?
- How to disable resizable property of textarea using CSS?
- How to disable zoom on a mobile web page using CSS?
- Parallax scrolling effect using CSS.
- How to create Glowing Star effect using HTML and CSS?
- Double Layered Text Effect using CSS
- CSS | Shadow Effect
- CSS Rain and lightning effect
- How to create fade-in effect on page load using CSS ?
- How to add a pressed effect on button click in CSS?
- How to Create Paradoxical Effect using CSS ?
- Loading Text Animation Effect using CSS
- How to Create Liquid Filing Effect on Text using HTML and CSS ?
- How to create shock wave or explosion effect using HTML and CSS ?
- How to Create Skeleton Screen Loading Effect using CSS ?
- How to Create Loading Blur Text Animation Effect using HTML and CSS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


