Created
February 15, 2010 23:29
-
-
Save cpinto/305094 to your computer and use it in GitHub Desktop.
dropdown with most recently clicked items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<select id="teste"> | |
<option>item 1</option> | |
<option>item 2</option> | |
<option>item 3</option> | |
<option>item 4</option> | |
</select> | |
<script src="js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(document).ready(function() | |
{ | |
$("#teste").change(function(o){ | |
var selected = $(this).find("option:selected"); | |
var mostrecent = $(this).find("optgroup#mostrecent"); | |
if (mostrecent.length == 0) | |
{ | |
mostrecent = $("<optgroup label='Mais recentes' id='mostrecent'/>"); | |
$(this).prepend(mostrecent); | |
} | |
if (selected.parent().get(0).id == "mostrecent") return; | |
mostrecent.prepend(selected.remove()); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment