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 jQuery Basics Working with jQuery Collections Stopping the Browser's Default Behavior

saving 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
Steven Parker
229,788 Points

Passing 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.

Awesome.. 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
Steven Parker
229,788 Points

Sure, formatting is done with "Markdown" code. You can find a Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

Happy coding!

Thank you