I have a list of element e.g.: .title, I’m cloning them out and append them to a container, but the order is reversed from prependTo`.
How do I put these cloned element to an array and reverse it before prepending them?
For example, for each .title clone it, and prependTo .container, and wrap it with li:
$('.title').each(function() {
$this.clone()
.prependTo('.container')
.wrap('<li></li>')
});
Given this html:
Use this jQuery to add them to the
.containerelement:If you want to reverse the order, then use
.prependinstead of.append.Check out http://jsfiddle.net/y8Aub/ if you want to see it in action.