- Prototype Tutorial
- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
- Prototype Useful Resources
- Prototype - Quick Guide
- Prototype - Useful Resources
- Prototype - Discussion
Prototype - getDimensions() Method
This method finds the computed width and height of element and returns them as key/value pairs of an object.
This method returns the correct values on elements whose display is set to none either in an inline style rule or in an CSS stylesheet.
Note that the value returned is a number, only although it is expressed in pixels.
Syntax
element.getDimensions();
Return Value
It returns key/value pairs of an object {height: Number, width: Number}.
Example
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function showResult() { var dimensions = $('rectangle').getDimensions(); alert("Element width is " + dimensions.width ); alert("Element height is " + dimensions.height ); } </script> </head> <body> <p>Click the button to see the result.</p> <div id = "rectangle" style = "font-size: 10px; width: 20em; height: 10em"> <p>This is the paragraph.</p> </div> <br /> <input type = "button" value = "showResult" onclick = "showResult();"/> </body> </html>
Output
prototype_element_object.htm
Advertisements