This little trick comes in handy if your site runs on a CMS. The editors within CMS's have a tendency to create multiple lists to markup the same set of elements – many times due to user error.
This approach could potentially be used for any type of element, but I imagine it would be most useful for ordered and unordered lists.
if ($('#content ul').length > 1) {
$('#content ul li').each(function(){
$('#content ul:first').append($(this));
$('#content ul').not(':first').remove();
});
}
Notes:
- We've dropped in a #content identifier, to ensure that this script doesn't adjust any lists which are part of your template (drop-down navigation, for example).
- If you are using a more recent version of jQuery, you may wish to swap out the :first selector for .first()