Prototype - clonePosition() Method



This method clones the position and/or dimensions of source onto element as defined by the optional argument options.

Syntax

element.clonePosition(source[, options]);

Here is the list of possible options −

Name Default Description
setLeft true clones source's left CSS property onto element.
setTop true clones source's top CSS property onto element.
setWidth true clones source's width onto element.
setHeight true clones source's width onto element.
offsetLeft 0 Number by which to offset element's left CSS property.
offsetTop 0 Number by which to offset element's top CSS property.

Return Value

An HTML element.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function clonePosition() {
            var firstElement = $('firstDiv');
            var secondElement = $('secondDiv');
            secondElement.clonePosition( firstElement);
         }
      </script>
   </head>

   <body>
      <p>Click Clone Position button to see the result.</p>
      <div id = "firstDiv">
         <p>This is first paragraph</p> 
      </div>

      <div id = "secondDiv">
         <p>This is second paragraph</p> 
      </div>
      <br />
      
      <input type = "button" value = "Clone Position" onclick = "clonePosition();"/>
   </body>
</html>

Output

prototype_element_object.htm
Advertisements