poner un div encima de otro div in javascript

Here is an example of how you can place one div on top of another div using JavaScript:

<body>
  <div id="div1">
    This is the first div
  </div>
  <div id="div2">
    This is the second div
  </div>
</body>
122 chars
9 lines
index.tsx
const div1 = document.getElementById("div1");
const div2 = document.getElementById("div2");

div2.style.position = "absolute";
div2.style.top = div1.offsetTop + "px";
div2.style.left = div1.offsetLeft + "px";
209 chars
7 lines

This example uses position: absolute to position the second div at the same position as the first div. The offsetTop and offsetLeft properties are used to get the position of the first div, which is then used to position the second div using the top and left CSS properties.

related categories

gistlibby LogSnag