Js loop li list to get the index value of the last clicked li that clicked on the current li

    <li>1</li>
    <li>2</li>
    <li>3</li>

question: circular list, no matter how I click, what I want to get is the index value of the last clicked li of the current element

Mar.10,2021

sets the index value of the previous click to an attribute of window.
on the next click, display the property of window and then update the property.
does not need a loop.


declares that a variable holds the index value of the click. Var index
for example, say index=1
know index=1
on the second click, and then save the index of the second click index=2


then store a key in the outer layer of the event to record the last click index


<ul>
    <li data-index="1">1</li>
    <li data-index="1">2</li>
    <li data-index="1">3</li>
</ul>
jquery
var beforeIndex = '' //index
$('ul').on('click','li',function(){
    console.log('beforeIndex',beforeIndex ) // index
    beforeIndex = $(this).data('index')
})
.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38fd3-e6a9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38fd3-e6a9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?