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

Libor Gess
Libor Gess
6,880 Points

The small challenge

What is better solution when I need to append new elements to the website?

The teacher wrote the line of code like this:

const $confirm = $('<label><input type="checkbox">Allow PDF downloads</lable>');
$('#links').append($confirm);

I wrote the code like this:

const $label = $('<label></label>');
const $input = $('<input>');

$input.attr('type', 'checkbox');

$('#links').append($label);
$label.text('Allow PDF downloads');
$label.prepend($input);

I think the teacher's code is simple.

1 Answer

Both Solutions are perfectly valid but the method the teacher used is easier to read, good work on coming up with a working solution that was different.