Javascript include menu with external file


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. This goes in your HTML where you want the menu, or other file, to appear:
  2.  
  3. <script language="JavaScript" type="text/javascript" src="js/menu.js"></script>
  4.  
  5.  
  6. Create a new file called "menu.js"
  7.  
  8.  
  9. document.write('<ul class="menu">');
  10.  
  11. // START LINKS //
  12.  
  13. <!-- Copy and paste to add more links. Note the first link starts the list, so don't copy that. -->
  14.  
  15. document.write('<li>');
  16. document.write('<a href="index.html" class="menu">Home</a>');
  17.  
  18. document.write('</li><li>');
  19. document.write('<a href="about.html" class="menu">About Us</a>');
  20.  
  21. document.write('</li><li>');
  22. document.write('<a href="services.html" class="menu">Services</a>');
  23.  
  24. document.write('</li><li>');
  25. document.write('<a href="gallery.html" class="menu">Photo Gallery</a>');
  26.  
  27. document.write('</li><li>');
  28. document.write('<a href="testimonials.html" class="menu">Testimonials</a>');
  29.  
  30. document.write('</li><li>');
  31. document.write('<a href="contact.html" class="menu">Contact Us</a>');
  32.  
  33. document.write('</li>');
  34.  
  35. // END LINKS //
  36.  
  37. document.write('</ul>');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.