Get which key was pressed

for the following html

    <div id="buttons">
        <button order="1" onclick="showImg()">1</button>
        <button order="2" onclick="showImg()">2</button>
        <button order="3" onclick="showImg()">3</button>
        <button order="4" onclick="showImg()">4</button>
        <button order="5" onclick="showImg()">5</button>
    </div>

how do I need js to get its order when a button is pressed?

Mar.16,2021

const order = event.target.getAttribute('order')

it is not recommended to write the event function on the html page. The js can be obtained as follows: first iterate through each button, and then use the getAttribute function to get the custom attribute value


 <div id="buttons">
        <button order="1" onclick="showImg()">1</button>
        <button order="2" onclick="showImg(this)">2</button>
        <button order="3" onclick="showImg(this)">3</button>
        <button order="4" onclick="showImg(this)">4</button>
        <button order="5" onclick="showImg(this)">5</button>
    </div>
    
    <script>
       function showImg(e){
          let order = e.target.order;    
       }
    </script>
    
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-1b3b503-2bace.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-1b3b503-2bace.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?