treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Dom traversion: find "," ??

  • Hi all,

    Say I have the following markup:
    <a href=\"#\">a link</a>, <a href=\"#\">another</a>,

    and this jQuery:
     $('a').click(function() {
    $(this).fadeOut(300);
    return false
    });


    When you click the link it'll fade out, so far so good. What if I want to include the following "," (comma) as well? How do I target that?

    Thanks,
    Oskar
  • You can't target anything unless it has some tag of some kind around it in order to target.

    <a href=\"#\">a link</a><span class=\"comma\">,</span> <a href=\"#\">another</a>


    Now you can target it with $(".comma")
  • Aha, that was what I was afraid of. I ended up using your method with $(this).next().fadeOut(); Works fine.

    Thank you! Now I've got a sweet ass module for clicking tags to posts ;-)