我需要使用jQuery指定顶级LIs的帮助

我需要使用jQuery指定顶级LIs的帮助,jquery,append,Jquery,Append,我试图限制append函数,使其仅适用于顶级LIs,但我显然不知道如何进行选择。在过去的几天里,我一直在寻找能指引我走向正确方向的东西,但到目前为止,我还没有找到运气 我只希望在顶层使用向下箭头,在后续LIs中使用向右箭头。希望这会有意义。这是我正在使用的代码 $("ul.dropdown li:has(ul)").find("a:first").append('<img class="down_arrow" border="0" style="padding-left:3px;" src

我试图限制append函数,使其仅适用于顶级LIs,但我显然不知道如何进行选择。在过去的几天里,我一直在寻找能指引我走向正确方向的东西,但到目前为止,我还没有找到运气

我只希望在顶层使用向下箭头,在后续LIs中使用向右箭头。希望这会有意义。这是我正在使用的代码

$("ul.dropdown li:has(ul)").find("a:first").append('<img class="down_arrow" border="0" style="padding-left:3px;" src="http://nunyabiz.zxq.net/img/down.gif" />')
$("ul.dropdown li ul li:has(ul)").find("a:first").append('<img class="right_arrow" border="0" style="padding-left:3px;" src="http://nunyabiz.zxq.net/img/right.gif" />');
$(“ul.dropdown li:has(ul)”).find(“a:first”).append(“”)
$(“ul.dropdownlli-li:has(ul)”).find(“a:first”).append(“”);
要查看完整代码:

使用选择器

$(“ul.dropdown>li:has(ul)”)。查找(“a:first”)。追加(
$("
或者你是怎么做到的:

$("ul.dropdown > li:has(ul)")
    .find("a:first")
    .append('<img class="down_arrow" border="0" style="padding-left:3px;" src="http://nunyabiz.zxq.net/img/down.gif" />')
$(“ul.dropdown>li:has(ul)”)
.查找(“a:第一个”)
.append(“”)

这很好

谢谢Hunter!为了防止其他人遇到这个问题并需要解决方案,我所要做的就是更改:$($ul.dropdown li:has(ul)”).find(“a:first”).append(“”)to this:$($ul.dropdown>li:has(ul)”.find(“a:first”).append(“”)你可能喜欢创建这样的元素,现在是超级duper性感时代
$("ul.dropdown > li:has(ul)")
    .find("a:first")
    .append('<img class="down_arrow" border="0" style="padding-left:3px;" src="http://nunyabiz.zxq.net/img/down.gif" />')