Advertisement
SailorFini

Javascript Section of Website

Aug 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function openCity(evt, cityName) {
  2.     // Declare all variables
  3.     var i, tabcontent, tablinks;
  4.  
  5.     // Get all elements with class="tabcontent" and hide them
  6.     tabcontent = document.getElementsByClassName("tabcontent");
  7.     for (i = 0; i < tabcontent.length; i++) {
  8.         tabcontent[i].style.display = "none";
  9.     }
  10.  
  11.     // Get all elements with class="tablinks" and remove the class "active"
  12.     tablinks = document.getElementsByClassName("tablinks");
  13.     for (i = 0; i < tablinks.length; i++) {
  14.         tablinks[i].className = tablinks[i].className.replace(" active", "");
  15.     }
  16.  
  17.     // Show the current tab, and add an "active" class to the button that opened the tab
  18.     document.getElementById(cityName).style.display = "block";
  19.     evt.currentTarget.className += " active";
  20. }
  21. <button class="tablinks" onclick="openCity(event, 'About')" id="defaultOpen">About</button>
  22.  
  23. { <script>
  24. // Get the element with id="defaultOpen" and click on it
  25. document.getElementById("defaultOpen").click();
  26. </script> }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement