开发者

jquery(selector) how to select the last element from two different classes

开发者 https://www.devze.com 2022-12-29 01:59 出处:网络
for the following html <div> <div class=\"col1\" > I dont want to select this </div> <div class=\"col2\">

for the following html

<div>
    <div class="col1" >
         I dont want to select this
    </div>
    <div class="col2">
         I dont want to select this
    </div>
    <div class="col1">
         I dont want to select this
    </div>
    <div class="col1">
         I dont want to select this
    </div>
    <div class="col2"&g开发者_开发知识库t;
         I WANT to select this
    </div>
</div>

How do I select the last element with two different class names?

Tried using

$("col1:last,col2:last)

but it gives back 2 elements

tried

$("col1,col2:last")

and this gives all col1 and last of col2


First get all elements with any of the class names, then pick the last one:

$('.col1,.col2').filter(':last')


try the last() method.

$(".col1,.col2").last();

0

精彩评论

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