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

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
229,732 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
229,732 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.