last element with a class name in a div

前端 未结 3 1682
渐次进展
渐次进展 2020-12-13 13:45

how can i get the last div with class a in a div the id = test ? in this case i have to get the div with content = 1000

相关标签:
3条回答
  • 2020-12-13 14:12
    $('div#test div:last-child');
    
    0 讨论(0)
  • 2020-12-13 14:21

    You can use the :last pseudo-selector:

    $('#test div.a:last')
    
    0 讨论(0)
  • 2020-12-13 14:34

    Without jQuery:

    var divs = document.getElementById("test").getElementsByTagName("div");
    var lastChild = divs[divs.length - 1];
    
    0 讨论(0)
提交回复
热议问题