Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Melissa Preece
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Melissa Preece
Full Stack JavaScript Techdegree Graduate 18,394 Points

Why not use the JQuery each() method on challenge no. 3?

I got challenge number 3 wrong, as I used the each() method on the 'a' elements. Why not use it since we are iterating through all the list items' anchor tags?

Steven Parker
Steven Parker
220,696 Points

Can you provide a link to the course page? And please show your code.

Melissa Preece
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Melissa Preece
Full Stack JavaScript Techdegree Graduate 18,394 Points

Sorry! https://teamtreehouse.com/library/practice-working-with-jquery-collections, specifically the 3rd challenge in the app.js instructions.

This is the correct answer: $('a').attr('target', '_blank'); I deleted mine as I was going through the solution, but I don't understand why this is the case. Thanks in advance!

1 Answer

Steven Parker
Steven Parker
220,696 Points

One of the advantages of jQuery is that when a jQuery object identifies a collection of elements, methods applied to that object affect all of the elements in the collection. So the "each" method is not needed.

The main reason you might use "each" is when you want to so something with the collection that cannot be done by one of the built-in methods.