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 trialYoan Herrera
21,137 Pointssaving a string in a jQuery selector??
Any specific reason why the instructor is saving the label html in a $(''). Using just a plain string const checkbox = "<label><input type='checkbox'> Allow PDF downloads</label>"
1 Answer
Steven Parker
231,236 PointsPassing the HTML string to jQuery creates a new element. Now, it happens that the .append
method will take either an element or a string as an argument, so it will work either way, but having an element might be handy in case you wanted to perform some other function on it. You might want to add a class or other attribute to it, for example.
Yoan Herrera
21,137 PointsYoan Herrera
21,137 PointsAwesome.. Thank you. makes sense.! y the way. do you know how to format code snippets, so it doens't look all jumbled together when posting a question??
Steven Parker
231,236 PointsSteven Parker
231,236 PointsSure, formatting is done with "Markdown" code. You can find a Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
Happy coding!
Yoan Herrera
21,137 PointsYoan Herrera
21,137 PointsThank you