DEV Community


Write your nav and footer only once with Javascript (safely)

christinavoudouris profile image christina Updated on ・1 min read

For an embarrassingly long time (in hindsight), I never knew or bothered to figure out how to create reusable code with vanilla Javascript. It just didn't feel like much effort to cut and paste navbars and footers on a handful of pages. Yet React components felt like a godsend.

Also not great: I used .innerHTML sometimes in my code which is not good practice. Enter .insertAdjacentHTML and now we're cooking with gas.

Check out a starter I made on Glitch for reference!

Discussion (0)

Editor guide