Skip to content

Instantly share code, notes, and snippets.

@Jayaramki
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jayaramki/11036879 to your computer and use it in GitHub Desktop.
Save Jayaramki/11036879 to your computer and use it in GitHub Desktop.
Reverse DOM elements usign jquery
<!--Here is the HTML code-->
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
<div class="child">5</div>
</div>
<input type="button" id="btn" value="Show DESC">
//Here is the Javascript code
$('#btn').click(function () {
if (this.value == 'Show ASC') this.value = 'Show DESC';
else this.value = 'Show ASC';
var list = $('div.parent');
var listItems = list.children('div.child');
list.append(listItems.get().reverse());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment