Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Prototype getWidth() Method


previous next AddThis Social Bookmark Button


Advertisements

This method finds and returns the computed width of element.

This method returns 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.getWidth();

Return Value:

  • It returns the computed width of element.

Example:

<html>
<head>
<title>Prototype examples</title>
<script type="text/javascript" 
   src="/javascript/prototype.js">
</script>
<script>

function showResult(){
   var width = $('rectangle').getWidth();
   alert("Element width is " +  width );
}
</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>

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements