English subtitles

← Changing Attributes Quiz - Intro to jQuery

Get Embed Code
6 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. Changing DOM element CSS classes is super useful.
  2. And likewise, sometimes you want to change attributes on DOM elements as well.
  3. Take a look at this unordered list in the header at the top of the page.
  4. Each of the list elements has an embedded a tag.
  5. You can see that the first element at the top of the list is missing its href.
  6. I want you to use jQuery to set its href to number 1 to match the hrefs of
  7. the other elements in this list.
  8. You'll be using the .attr method to add an href.
  9. .attr is interesting in that it has two different method signatures.
  10. With the first signature,
  11. if you pass in the string of an attribute, you can get its value.
  12. And with the other, you can set the value of an attribute by passing in
  13. a string for the second parameter.
  14. This is a common pattern for
  15. methods that interact with data saved on a DOM element.
  16. So, using .attr, can you change the href of this a tag to be equal to number 1?
  17. Here's a hint.
  18. You might need another method like .first to help out.