开发者

last element with a class name in a div

开发者 https://www.devze.com 2022-12-17 02:54 出处:网络
how can i get th开发者_Go百科e last div with class a in a div the id = test ? in this case i have to get the div with content = 1000

how can i get th开发者_Go百科e last div with class a in a div the id = test ? in this case i have to get the div with content = 1000

<div id="test">
<div class="a">1</div>
..
..
<div class="a>1000</div>
</div>


You can use the :last pseudo-selector:

$('#test div.a:last')


Without jQuery:

var divs = document.getElementById("test").getElementsByTagName("div");
var lastChild = divs[divs.length - 1];


$('div#test div:last-child');


using the proposed at

const nodesHighlighted = document.querySelectorAll('.day--highlight');
const lastNodeHighlighted = [...nodesHighlighted].at(-1);

at the current writing it's not supported by safari

0

精彩评论

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