The goal of this activity is to move the embedded Javascript and CSS in index.html to external files without breaking the page.
- Download or fork/clone this Gist into your workspace.
- Move the Javascript currently in the
scriptelement to an external file calledscript.js. Delete the now emptyscriptelement. - In
index.html, link to this new Javascript file by adding a newscriptelement in theheadof the HTML file.- Use the
srcattribute to relatively link to the new Javascript file you just created. - Add an attribute of
deferto thescriptelement. This ensures that the Javascript loads after the DOM has loaded (this is the same as putting thescriptat the bottom of the page).
- Use the
- Test the page to make sure it still functions normally (colours should change when you click the button).
- Move the CSS currently in the
styleelement to an external file calledstyles.css. Delete the now emptystyleelement. - In
index.html, link to this new Javascript file by adding a newlinkelement in theheadof the HTML file.- Use the
hrefattribute to relatively link to the new CSS file you just created. - Add an attribute of
rel="stylesheet"so browser knows how to properly load the CSS file.
- Use the
- Test the page to make sure it still functions normally (colours should change when you click the button).
Coming soon.