Web API DOMRect left property
In Web API there is a DOMRect Interface which has a property left that gives us the left of the DOMRect object. It returns the x coordinate value or if the width is negative then it returns x + width.
Syntax:
let recX = DOMRect.left;
Return Type:
Double value
Example 1: When the width is positive
HTML
<!DOCTYPE html> < html > < head > < title > DOMRect left property </ title > </ head > < body > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >DOMRect left property</ h2 > < button onclick = "getDOMRect ();" > Get left </ button > < p id = 'DOMRect' ></ p > < script type = "text/javascript" > function getDOMRect() { let myDOMRect = new DOMRect(0, 0, 100, 100); let recleft = myDOMRect.left; document.getElementById( 'DOMRect').innerHTML = recleft; } </ script > </ body > </ html > |
Output:
Example 2: When the width is negative
HTML
<!DOCTYPE html> < html > < head > < title > DOMRect left property </ title > </ head > < body > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >DOMRect left property</ h2 > < button onclick = "getDOMRect ();" > Get left </ button > < p id = 'DOMRect' ></ p > < script type = "text/javascript" > function getDOMRect() { let myDOMRect = new DOMRect(0, 0, -100, 100); let recleft = myDOMRect.left; document.getElementById( 'DOMRect').innerHTML = recleft; } </ script > </ body > </ html > |
Output:
Supported Browsers: The browsers supported by DOMRect left property are listed below:
- Google Chrome
- Safari 10.1
- Firefox
- Opera