I think all I need is a selector, but can't find one. I want to select the anchor tag, but can only select the li
using .parent()
...
jQuery:
$("nav ul li > ul").parent().append('<span class="arrow">↓</span>');
HTML:
<li><a href="#">The Events</a>
<ul>
<li><a href="#">Schedule</a></li>
开发者_如何学编程 <li><a href="#">Buy Tickets</a></li>
<li><a href="#">Features</a></li>
</ul>
</li>
The code above puts the arrow on the right li
s, but one level to high. I need to target the li
's a
tag.
You can use .siblings()
, like this:
$("nav ul li > ul").siblings("a").append('<span class="arrow">↓</span>');
You can find a full list of traversal functions here.
Answered myself. Using .children("a")
I was able to select the anchor. Final code looked like:
$("nav ul li > ul").parent().children("a").append('<span class="arrow">↓</span>');
Does this happen on clicking the link or onload?
精彩评论