Skip to content

Create a single reusable navigation menu and "include" or insert it into as many other HTML pages as you like. With a little Javascript. And oh Yeah: it's responsive!

Notifications You must be signed in to change notification settings

davidvandenbor/html-includes-with-standard-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Html includes with standard javascript

Play live with this code in Plunker > click here!

jump to code example in Plunker

An example of how you can include "snippets" of HTML into other HTML pages. This might come in handy for things like including headers, footers, menu's or sidebars to multiple pages of a website or application. For instance, you can embed a snippet of code into 20 or 30 webpages simultaniously: a single top bar navigation menu which was saved as a reusable piece of code in a seperate text or HTML file. It takes just a couple of lines of javascript to do this.

jump to code example in Plunker

As a bonus, I've also added a few lines of code that sticks an ".active" css class on the menu item (with the name of the currently loaded page). It does this by checking the URL that's actively present in the address bar of your browser, and then looping over the menu items to see if it matches the name of the menu link.

jump to code example in Plunker

See it live

See a working version online that you can download (ZIP) or edit live in Plunker: https://embed.plnkr.co/github/davidvandenbor/html-includes-with-standard-javascript

About

Create a single reusable navigation menu and "include" or insert it into as many other HTML pages as you like. With a little Javascript. And oh Yeah: it's responsive!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published