HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <p>Hello <span>Span</span></p> <p>Click on the button to display the css value (width, height, etc,.) of span relative to the viewport.</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var elem = document.getElementsByTagName("span")[0]; function myFunction(){ var rect = elem.getClientRects()[0]; var txt = ""; txt += "<br>Width : " +rect.width; txt += "<br>Height : " +rect.height; txt += "<br>From Left : " +rect.left; txt += "<br>From Right : " +rect.right; txt += "<br>From Top : " +rect.top; txt += "<br>From Bottom : " +rect.bottom; x.innerHTML = txt; } </script> </body> </html>
OUTPUT
×

Save as Private