How to set the stack order of a positioned element in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

To set the stack order, use the zIndex property. You can try to run the following code to implement zIndex property in JavaScript −

Example

<!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>
raja
Published on 27-Feb-2018 10:35:52
Advertisements