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 trialEwerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsWhy this second task won't work?
The video containing the practice I'm referring to: https://teamtreehouse.com/library/practice-handling-events-in-jquery
Snapshot: https://w.trhou.se/cowta9tlc2
I tried writing the code like it is in the js/app.js file, but it doesn't work properly. It adds a li item to the ul, but is an empty li item.
I am playing around to see if jQuery works mixed with plain javascript. Does it? I'm not sure =// Tried Google, but I'm still not sure
1 Answer
Steven Parker
231,248 PointsThe jQuery library extends JavaScript, and is completely compatible with it. But it's important to observe the difference between the kind of objects you are using.
Your "li" variable is a jQuery object, not an HTML element. Adding to the "textContent" property is something you might do with an HTML element.
The jQuery equivalent is calling the "text" method:
const li = $("<li></li>"); // (the closing ">" was missing in the workspace)
li.text(restaurantName); // add text with the jQuery method
$("ul").append(li);
A common convention that helps avoid confusion is to name variables that refer to jQuery objects starting with a dollar sign ($). So in this case you might name the variable "$li
".
Ewerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 Pointsbest answer I got from this so far, after making some research. Thank you, Steven!
Lauren Eggers
Full Stack JavaScript Techdegree Graduate 17,960 PointsLauren Eggers
Full Stack JavaScript Techdegree Graduate 17,960 PointsYou're literally just adding "<li></li>" and later targeting li.textContent but... doesnt target that particular li you just made. You could concatenate the restaurantName. Alternatively, you could $("ul").append(li.textContent = restaurantName);