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 trialGraham Huelscher
7,003 PointsIs the $ sign required when creating a new element
Just wondering if the "$" sign is required when creating a new html element with jquery. I tried:
const $button = ('<button>Reveal Spoiler</button>');
and it seems to be working fine as well. Just wanted some clarification before moving forward because the video made it seem like it was required.
Additionally, the following quiz seems to omit it when asked to fill in the blank to create a new element.
"Use the appropriate jQuery method to create and insert a NEW element into the DOM.
$('.my-element')._________('<p>This is a new paragraph element</p>');"
1 Answer
Steven Parker
231,236 PointsWithout the $ sign (and then you also don't need the parentheses), your variable contains a string instead of an element. You didn't notice the difference because the only thing you use it for is to pass it to a function which can take either an element or a string as an argument.
It would make a difference if you needed to perform some element-related function on it, such as styling it with ".css()
".