views:

36

answers:

3

I am a little confused on how prepend acts towards a children function.

image.canvas.children('.image-pinpoint-view').prepend(this.area);

where would this.area appear?

+2  A: 

It adds this.area (or a clone) as the first child of every matching child of image.canvas. Matching children are those with the image-pinpoint-view class. A DOM node can only be in one place, but jQuery will clone the element so there's one for each desired parent.

Matthew Flaschen
A: 

Prepend puts the specified content at the beginning of the element.

<div id="content">
   <div id="a">data</div>
</div>

$('#content').prepend('<div id="b">prepended data</div>');

would result in

<div id="content">
   <div id="b">prepended data</div>
   <div id="a">data</div>
</div>

$('#content').prepend( $('#a') );

would result in

<div id="content">
       <div id="a">data</div>
       <div id="b">prepended data</div>
    </div>
Dan Heberden
A: 

Every jQuery object is an array. Every jQuery method is applied to all elements. If you write:

 $(".elements").css(...) 

...the style will be applied to all elements.

Similarly, in your case, the element (this.area) will be cloned and one clone will be inserted before each children.

See it in action.

galambalazs
not _Always_ the case if the element is already a child. instead of cloned, it's index is adjusted. http://jsfiddle.net/tq54g/1/
Dan Heberden