Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าลำดับชั้นขององค์ประกอบที่จัดตำแหน่งใน JavaScript


หากต้องการตั้งค่าลำดับชั้น ให้ใช้คุณสมบัติ zIndex  คุณสามารถลองรันโค้ดต่อไปนี้เพื่อนำ zIndex ไปใช้ใน JavaScript −

ตัวอย่าง

<!DOCTYPE html> <html>    <head>       <style>          #myID {             position: absolute;             left: 20px;             top: 20px;             z-index: -1          }       </style>    </head>    <body>       <img id = "myID"          src="https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg"          width = "150" height = "150">       <button type="button" onclick="myFunction()">Set Stack Order</button>       <p>Z-index is -1</p>       <script>          function myFunction() {             document.getElementById("myID").style.zIndex = "1";          }       </script>    </body> </html>