Nasir
Nasir

Reputation: 4865

How do I get the last <li> item in a unordered list & place it at the top of the list, using JQuery?

I was wondering is there any way to get the last item in a unordered <ul> list and place it at the top of the list...kind of like a continuous loop?

Sorry I'm a novice at JQuery

Any help is greatly appreciated, Thanks

Upvotes: 1

Views: 565

Answers (1)

Nick Craver
Nick Craver

Reputation: 630389

You can use .prepend() or .prependTo(), like this:

$("#myUL li:last").prependTo("#myUL")

This uses :last to get the last one them prepends it to the same list, inserting it at the beginning.

Upvotes: 4

Related Questions