I am trying to do some simple DOM manipulations on multiple elements at once using jQuery using each (). I get results that I don’t understand.
Here is a jsFiddle that shows what I want to do VS, what actually happens:
http://jsfiddle.net/kthornbloom/4T52A/2/
And here is the JS:
// Step One: Append one blue box within each grey box $('.grey').append('<div class="blue"></div>'); // Step Two: Make one copy of the red box already there, and place it within the new blue box. $('.grey').each(function () { $('.red', this).clone().appendTo('.blue', this); });
Why do I get the results that I have, and how can I achieve the desired results?
javascript jquery dom this each
kthornbloom
source share