@OP:

I don't think clonePosition works on inline-positioned elements, I
think they have to have the style "position: absolute".  You may be
able to use Element#absolutize[1] to make them absolutely positioned,
but that will take them out of the flow (and so other things may
move).

Separately, can I recommend not using DOM0 (onclick attribute and the
like) handlers, use Element#observe / Event.observe instead[2][3].

[1] http://prototypejs.org/api/element/absolutize
[2] http://prototypejs.org/api/element/observe
[1] http://prototypejs.org/api/event/observe

HTH.

@Marslander:

> No, you did. <button onclick='function()'> == this.function().

No, that's not quite correct.  If that were the case, then within the
function "this" would refer to the button, and it doesn't, it refers
to the window.  "this" is only the clicked element in a DOM0 handler
within the actual handler (in this case, the quoted bit), not
functions called from it (unless, again, you explicitly use "this."
when calling them).  This is trivial to test:

<input type='button' id='mybutton' onclick='someFunction()' />

function someFunction()
{
    alert("this.id == " + this.id);
    alert('this === window? ' + (this === window));
}

That gives you two alerts:

"this.id == undefined"
"this === window? true"

Whereas this:

<input type='button' id='mybutton' onclick='$(this).remove();' />

...successfully calls the remove method of the button.  Note that in
order to work with IE, you have to run it through $() -- if you don't,
the element is not extended by default.

The OP is (somewhat confusingly) calling his *own* clonePosition
function, which in turn uses the Element#clonePosition function.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On May 18, 11:42 am, Marslander <yazev...@gmail.com> wrote:
> No, you did. <button onclick='function()'> == this.function().
>
> On May 15, 3:34 pm, Alaa <ala...@gmail.com> wrote:
>
> > Thank u for reply, But I did not use "this" word in my code!!!
>
> > On May 14, 3:13 pm, Marslander <yazev...@gmail.com> wrote:
>
> > > That is because you call Prototype method 'this.clonePosition' by
> > > clicking your button. In this case 'this' - is the button itself
> > > (extended element). You need to rename your 'clonePosition' function.
>
> > > On May 13, 2:54 pm, Alaa <ala...@gmail.com> wrote:
>
> > > > Hello,
> > > > From it is name I expect that the two elements will have the same
> > > > position after cloning the position, but nothing happens!!!
>
> > > > here is the 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>
>
> > > > So, is that a bug, or I have some mistakes, or it is not doing as I
> > > > have understood???
>
> > > > help please
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to