Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Noah Fields
13,985 PointsJavascript - Determine Child Event Occurred On
Currently I'm working on a personal project wherein I create a reading schedule, determining progress through a given book and whether or not the user is "on track" for completion. Currently the project is mostly functional, with an event handler activating and working as intended for each list element (representing a page or chapter). However, in order to determine whether or not the user is "on track" or not it it is necessary to know which numbered child was activated (for instance, the 50th child out of a 100 page book). Though each child is given a number when generated by JavaScript I'm not certain how to go about extracting that number into a variable, so that I can use it for comparisons.
Snapshot is here: https://w.trhou.se/nr01qk06lu
This program is written in Brackets, and because of this Treehouse's preview feature is a little awkward with it. To view the page itself you have to navigate through the directory a little, or you can simply download the files and view them that way.
1 Answer
Tobiasz Gala
Full Stack JavaScript Techdegree Student 23,529 PointsSince you have text node next to generated checkbox you can use previousSibling on change event
e.target.previousSibling;
You can add generated number to h1 element instead of plain text if you plan doing some extra css work. In this case use .previousElementSibling