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

Robert Young
Robert Young
11,579 Points

My solution for 'Practice working with jQuery collections'

Here is my solution to this practice:

//1. Add a "featured" tag to the second item in the list:
const $featured = ('<span>Featured</span>');
  //  Append a new span element containing the word "Featured" to the list item
  $('#restaurantList li').eq(1).append($featured);
  //  Add a class of "featured" to the new span element. 
  $('#restaurantList li span').addClass('featured');
//2. Add a class of "new" to the last item in the list. You can traverse to the last item or find a jQuery method that helps you select the last item in the list. 
$('#restaurantList li:last-of-type').addClass('new');
//3. Add an attribute to each link so that all anchor tags open in a new tab. 
$('#restaurantList li a').attr('taget', '_blank');
//4. Select and print the index and text of each anchor tag to the console
$('#restaurantList li a').each(function(){
  const $text = $(this).text();
  console.log(`${$text}`);
});