Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function openCity(evt, cityName) {
- // Declare all variables
- var i, tabcontent, tablinks;
- // Get all elements with class="tabcontent" and hide them
- tabcontent = document.getElementsByClassName("tabcontent");
- for (i = 0; i < tabcontent.length; i++) {
- tabcontent[i].style.display = "none";
- }
- // 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 button that opened the tab
- document.getElementById(cityName).style.display = "block";
- evt.currentTarget.className += " active";
- }
- <button class="tablinks" onclick="openCity(event, 'About')" id="defaultOpen">About</button>
- { <script>
- // Get the element with id="defaultOpen" and click on it
- document.getElementById("defaultOpen").click();
- </script> }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement