Chapter projects
Build your own analytics
Figure out which elements are clicked on in a page and record their IDs, tags, and class name.
- Create a main container element within your HTML.
- Add four elements inside the main element, each having a class of
box
and a unique ID with unique text content. - Set up your JavaScript code to contain an array that you can use for tracking, adding details from each click into it.
- Select the main container element as a variable object in your code.
- Add an event listener to capture clicks on the element.
- Create a function to handle the clicks. Get the target element from the event object.
- Check if the element has an ID, so that you don't track clicks on the main container.
- Set up an object to track the values; include the element
textContent
,id
,tagName
, andclassName
. - Add the temporary object to your tracking array.
- Output the values captured in your tracking array to your...