Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  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.  
  22. <!-- Tab links -->
  23. <div class="tab">
  24. <button class="tablinks" onclick="openCity(event, 'London')">London</button>
  25. <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
  26. </div>
  27.  
  28. <!-- Tab content -->
  29. <div id="London" class="tabcontent">
  30. <h3>London</h3>
  31. <p>London is the capital city of England.</p>
  32. </div>
  33.  
  34. <div id="Paris" class="tabcontent">
  35. <h3>Paris</h3>
  36. <p>Paris is the capital of France.</p>
  37. </div>
  38.  
  39. <script type="text/javascript" src="javascript/ajax_openCity.js"> </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement