开发者

I need help with specifying the top level LIs only using jQuery

开发者 https://www.devze.com 2023-03-09 00:49 出处:网络
I\'m trying to restrict the append function so that it only applies to the top level LIs, but I obviously have no idea how to be that selective. I\'ve searched for the last few days hoping to find som

I'm trying to restrict the append function so that it only applies to the top level LIs, but I obviously have no idea how to be that selective. I've searched for the last few days hoping to find something that will lead me in the right direction, but no luck so far...

I only want the down arrow to be used in the top level, and the right arrow to be used on subsequent LIs. Hopefully this will make sense. Here's the code that I'm using.

$("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").appe开发者_运维问答nd('<img class="right_arrow" border="0" style="padding-left:3px;" src="http://nunyabiz.zxq.net/img/right.gif" />');

To see the full code: http://nunyabiz.zxq.net/menu/index.html


using the Child Selector (“parent > child”) selector

$("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"
    })
);

or how you had it:

$("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" />')

which is just OK

0

精彩评论

暂无评论...
验证码 换一张
取 消