JavaScript element.getClientRects() Method
You are Here:
JavaScript element.getClientRects() Method
The element.getClientRects()
method returns a collection of DOMRect objects that indicate the bounding rectangles for each CSS border box in a client.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p>Hello <span>Span</span></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>
Syntax
element.getClientRects()
Return Values
Value | Explanation |
---|---|
Object | Returns a collection of rectangles that indicate the bounding rectangles for each line of text in a client. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.