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>
<script src=""></script>
<script type="text/javascript">
    var divsTotal = $('#parent div').length-1;
    var divId = $('#parent div:nth-child(' + divsTotal + ')').attr('id');
Be a part of the DaniWeb community

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