English subtitles

← Removing DOM Elements Solution - Intro to jQuery

Get Embed Code
5 Languages

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

  1. I'll start by creating a JQuery collection of all the elements of
  2. class article-item.
  3. Then I'll call find on the article-items, and
  4. pass it ul to find all instances of unordered lists in the collection.
  5. Now, I have to be careful.
  6. I am actually telling jQuery to select all ul's from any of the article-items.
  7. In this case, I only have one, right here.
  8. But if I had more than one, I'd need to use a more specific selector or
  9. filter it somehow, otherwise I'd delete other ul elements.
  10. At this point I'll simply remove the ul and presto, it is gone.
  11. Alternatively, according to the documentation, you can
  12. also pass a selector into .remove to only remove specific elements from the DOM.
  13. For instance, if you only wanted to remove elements with class bold,
  14. you could pass in the selector .bold and you'd only see James disappear.
  15. You can hit Test.
  16. Scroll down, and James is gone.