DEV Community

Discussion on: 7 Javascript Methods That Aid DOM Manipulation

Collapse
 
drozerah profile image
Drozerah • Edited

I have recently discovered the Element​.get​Bounding​Client​Rect() , the method give the left, top, right, bottom, x, y, width, and height of DOM element :

function myFunction() {
  var div = document.getElementById("myDiv");
  var rect = div.getBoundingClientRect();
  x = rect.left;
  y = rect.top;
  w = rect.width;
  h = rect.height;
  alert ("Left: " + x + ", Top: " + y + ", Width: " + w + ", Height: " + h);
}


`
pretty neat ! isn't it ?

Collapse
 
desoga profile image
deji adesoga

Yes it is and good find too.