jQuery - 选择列表中最后一个LI的每个UL

时间:2022-11-27 21:29:55

I'm trying to format my list of items, where the html goes like this:

我正在尝试格式化我的项目列表,其中html如下所示:

<ul class='product_list'>
<li>Item 1
    <ul>
        <li>Item 1.1</li>
        <li>Item 1.2
            <ul>
                <li>Item 1.2.1</li>
                <li>Item 1.2.2
                    <ul>
                        <li>Item 1.2.2.1</li>
                        <li>Item 1.2.2.2</li>
                    </ul>
                </li>
            </ul>
        </li>
        <li>Item 1.3</li>
    </ul>
</li>
<li>Item 2</li>

And so on, hope you get the idea, that it can go deep infinet amout of times and now, I need to select and format UL of every LAST LI in any UL of the list.

等等,希望你能得到这个想法,它可以在很长一段时间内完成,现在,我需要在列表的任何UL中选择并格式化每个LAST LI的UL。

Do you have any idea? I've been stuck on this for 2 days now and all that I come up with has some "but", when it does't work. =/

你有什么主意吗?我已经坚持了2天了,我提出的所有内容都有一些“但是”,当它不起作用时。 = /

Mike

2 个解决方案

#1


2  

Try:

$("li:last-child > ul").css("border", "1px solid red");

Demo: http://jsfiddle.net/2NVB7/

#2


0  

CSS/jQuery selector: li:last-child > ul

CSS / jQuery选择器:li:last-child> ul

Note that there are compatibility issues with CSS.

请注意,CSS存在兼容性问题。

#1


2  

Try:

$("li:last-child > ul").css("border", "1px solid red");

Demo: http://jsfiddle.net/2NVB7/

#2


0  

CSS/jQuery selector: li:last-child > ul

CSS / jQuery选择器:li:last-child> ul

Note that there are compatibility issues with CSS.

请注意,CSS存在兼容性问题。