On Tue, May 19, 2009 at 10:48 AM, aly <he...@digitalnature.ro> wrote:
> > > thanks for your reply. > html is something like: > > <div class="mydivcontainer"> > ... > <div class="mydiv"> > ... > </div> > </div> > > there are more elements where I placed the (...) dots, but I guess it > doesn't matter since parent('.mydivcontainer') should locate the > target element. > and yes, what I am trying to do is move .mydiv and its contents at the > beginning of .mydivcontainer (just after <div > class="mydivcontainer">). > > I don't undestand why my 2nd example doesn't work. > that function should traverse each element with the .mydivclass and > clone it in .mydivcontainer, then remove the original element. or am I > wrong? prependTo already takes care of removing the original, and it returns the same element to you in its new location, and you're then removing it. - Richard > > > > On 19 Mai, 15:31, "Richard D. Worth" <rdwo...@gmail.com> wrote: > > And what is it you're trying to do exactly? I have to say I was caught > > curious by your subject 'Move element to parent div'. Where would an > element > > be, if not inside its parent? Are you just trying to move it up to be the > > first child of the parent, by prependTo? > > > > I wonder if in the first case, you're creating a bunch of clones, by a > > .prependTo(selector) with a selector that matches more than one element, > > then removing the original. And in the second case, you're moving the one > > element, then removing it. I haven't tested, but this is my best guess > just > > looking at your code, and without seeing your html. > > > > - Richard > > > > On Tue, May 19, 2009 at 8:27 AM, Richard D. Worth <rdwo...@gmail.com> > wrote: > > > > > > > > > What does your html look like? Is .mydivcontainer the immediate parent > of > > > .mydiv? > > > > > - Richard > > > > > On Tue, May 19, 2009 at 7:20 AM, aly <he...@digitalnature.ro> wrote: > > > > >> I'm trying to move a set of divs into their parent elements. > > > > >> Currently I'm using: > > >> jQuery('.mydiv').each(function(){ jQuery(this).prependTo > > >> ('.mydivcontainer').remove(); }); > > > > >> this works somehow, but the problem is that all elements on the page > > >> with class .mydiv are inserted into each .mydivcontainer element. > > > > >> to avoid this, I tried prepending .mydiv to its parent; > > >> jQuery('.mydiv').each(function(){ jQuery(this).prependTo(jQuery > > >> (this).parent('.mydivcontainer')).remove(); }); > > > > >> but for some weird reason it doesn't work, .mydiv doesn't show up :( > > > > >> can anyone help me with this? > > >> thanks :D >