Professional Documents
Culture Documents
asp
Hover Tabs
Move the mouse over one of the menu buttons to show the tab content:
London London
London is the capital city of England.
Paris
Tokyo
1 of 7 1/25/2022, 11:42 PM
How To Change Tabs on Hover https://www.w3schools.com/howto/howto_js_hover_tabs.asp
Try it Yourself »
Example
<div class="tab">
<button class="tablinks" onmouseover="openCity(event,
'London')">London</button>
<button class="tablinks" onmouseover="openCity(event,
'Paris')">Paris</button>
<button class="tablinks" onmouseover="openCity(event,
'Tokyo')">Tokyo</button>
</div>
Create buttons to open the specific tab content. All <div> elements with
class="tabcontent" are hidden by default (with CSS & JS) - when the user move
the mouse over a button - it will open the tab content that "matches" this button.
2 of 7 1/25/2022, 11:42 PM
How To Change Tabs on Hover https://www.w3schools.com/howto/howto_js_hover_tabs.asp
Example
/* Style the buttons that are used to open the tab content */
.tab button {
display: block;
background-color: inherit;
color: black;
padding: 22px 16px;
width: 100%;
border: none;
outline: none;
text-align: left;
cursor: pointer;
}
3 of 7 1/25/2022, 11:42 PM
How To Change Tabs on Hover https://www.w3schools.com/howto/howto_js_hover_tabs.asp
float: left;
padding: 0px 12px;
border: 1px solid #ccc;
width: 70%;
border-left: none;
height: 300px;
display: none;
}
Example
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the link that opened
the tab
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
4 of 7 1/25/2022, 11:42 PM
How To Change Tabs on Hover https://www.w3schools.com/howto/howto_js_hover_tabs.asp
Try it Yourself »
❮ Previous Next ❯
NEW
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing
5 of 7 1/25/2022, 11:42 PM
How To Change Tabs on Hover https://www.w3schools.com/howto/howto_js_hover_tabs.asp
a course today!
school
w3 s
2
CE
02
TI 2
R
FI .
ED
Get started
CODE GAME
Play Game
6 of 7 1/25/2022, 11:42 PM
How To Change Tabs on Hover https://www.w3schools.com/howto/howto_js_hover_tabs.asp
Get Certified »
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our
terms of use, cookie and privacy policy.
7 of 7 1/25/2022, 11:42 PM