Write code that handles the following action:
- When a user clicks on any
<p>
tag on a webpage, change the font of the<p>
tag that was clicked to comic sans.
You should be able to test your code by opening up a console on any webpage that has <p>
tags (so, pretty much any webpage... NY Times, Wikipedia, and Medium are fun) and pasting in your solution.
If you want some hints, expand the sections below.
Click to show Hint #1
HINT: You might need to loop over all the <p>
tags somehow, or use event delegation...
Click to show Hint #2
HINT: If wondering how to loop over all the <p>
tags, querySelectorAll is a nice way to access a collection of elements...
Click to show Hint #3
HINT: If you're not sure how to set an element's font to Comic Sans, here's one way to do it:
element.style.fontFamily = '"Comic Sans MS", cursive, sans-serif'