how can I get second last child's div id in JS?

Does it help you?

<div id="parent">
    <div id="id1">1</div>
    <div id="id2">2</div>
    <div id="id3">3</div>
    <div id="id4">4</div>
    <div id="id5">5</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    var divsTotal = $('#parent div').length-1;
    var divId = $('#parent div:nth-child(' + divsTotal + ')').attr('id');
    alert(divId);
});
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.