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 One Solution

David Regel
David Regel
Full Stack JavaScript Techdegree Student 5,504 Points

Question regardin jQuery

This is the task:

//4. Select and print the index and text of each anchor tag to the console
$('a').each(function(index, item){
  console.log(index, $(item).text());

Why do we have to use a $ (jQuery) in this function "$(item).text());"?

Why is just "item.text());" not working?

1 Answer

Hi David,

.text() is not a native method to vanilla JavaScript. In order to use the .text() method you must first access 'item' as a jQuery object by passing it to the jQuery() method, aka $().

Hope that helps!