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

JavaScript DOM Scripting By Example Adding and Removing Names RSVP Checkbox

Element checkbox before label 'confirmed'

How could I create and append element checkbox before label 'confirmed' ?

5 Answers

Steven Parker
Steven Parker
241,434 Points

If you wanted to place the checkbox before the label instead of inside it:

//  label.appendChild(checkbox);  // instead of doing this
    li.appendChild(checkbox);     // do this instead
Steven Parker
Steven Parker
241,434 Points

Oh, you didn't really want it before the label element itself, just before the text in the label:

    label.insertBefore(checkbox, label.firstChild); 

You are an actual genius. I see all your answers and comments everywhere are they are extremely helpful every single time!!

Samuel Cleophas yes he is indeed...Steven Parker beside awesome teachers at tree-house, we learn loads of stuffs from the community because you guys are here..thank you all.

Hi Steven Parker I tried it here...

https://codepen.io/Abhijeet_dasdezine/pen/LLMqEZ?editors=1010

however I want to get that Label for click and get input checkbox selection; like if i click on confirmed checkbox will select. It's not happening in this case.

Steven Parker
Steven Parker
241,434 Points

See the comment added to my answer.

Steven Parker thank you :)

Steven Parker
Steven Parker
241,434 Points

Glad to help. Happy coding!

Steven Parker done sir