I’m trying to write a bit of jquery which finds all h2 tags inside a div (.content), then appends each one into another div (.intro).
So far I have this:
var h2 = $(".content").find("h2");
$(h2).each(function() {
$(this).append(".intro");
});
But it’s not working.. if someone could help me out, that’d be great 🙂
Try this:
No need to use
each(). jQuery has something called “implicit iteration” where you can act on the entire set at once. So you can grab them all, and append them all at the same time.Or did you want to append a copy of them?
If so, try:
EDIT:
Or use a single line version:
(of course, remove
.clone()if you don’t need to copy them.)