Export (0) Print
Expand All

right property

Sets or retrieves the right coordinate of the rectangle surrounding the object content.

Syntax

JavaScript

p = object.right

Property values

Type: Integer

the right coordinate of the rectangle, in pixels.

Remarks

To access the right coordinate of the second text rectangle of a TextRange object, use this syntax:


oRct = oTextRange.getClientRects();
oRct[1].right;

Note that the collection index starts at 0, so the second item index is 1.

To access the right coordinate of the bounding rectangle of an element object, use this syntax:


oBndRct = oElement.getBoundingClientRect();
oBndRct.right;

Examples

This example uses the getBoundingClientRect method to retrieve the coordinates of the bounds of the text rectangles within the element.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/rectangles.htm


<!DOCTYPE html>

<html>
<head>
  <title>boundingTop</title>
</head>
<body>
  <p onclick="getCoords(this)" style="cursor: pointer">Click this text with the F12 Tools console window open.</p>
  <script>
    function getCoords(oObject) {
      var oBndRct = oObject.getBoundingClientRect();
      console.log("Bounding rectangle = \n  Upper left coordinates: (" 
        + oBndRct.left + ", " + oBndRct.top + ")"
        + "\n  Lower right coordinates: ("
        + oBndRct.right + ", " + oBndRct.bottom + ")");
    }
  </script>
</body>
</html>

See also

Reference
TextRectangle
bottom
left
top

 

 

Show:
© 2014 Microsoft