Reputation: 13
I have a little problem.
<li>
<a></a>
<span>Description 1</span>
</li>
<li>
<a></a>
<span>Description 2</span>
</li>
I want to append the span to the prev a without using a class or the content. Can you help me?
I tried something like this, but then I copy the span into each <a>
tag:
$('li span').appendTo($('li span').prev());
Thanks for any help!
Upvotes: 1
Views: 104
Reputation: 6647
Try this:
$('li').each(function(i, li) {
$(li).find('a').append($(li).find('span'));
});
jsfiddle. I added some colors and behaviors to show you it worked without looking at the dom
Upvotes: 0
Reputation: 95057
You could do it this way,
$("li a").append(function(){
return $(this).next();
});
Upvotes: 0
Reputation: 11840
Is this what you're looking to accomplish?
$('li span').each(function(){
$(this).appendTo( $(this).prev() );
});
Upvotes: 1