1

If I have a dropdown and a listbox, is there a way to order the listbox based on the dropdown using JQuery? An example would be helpful.

1 Answer 1

2

This alters the order in the pulldown. You'll have to set the order depending on your own criteria:

<select id="the-select">
    <option value="1">First option</option>
    <option value="2">Second option</option>
</select>

<script type="text/javascript">
//<![CDATA[
    $(function (){
        $("#the-select option[value=2]").insertBefore("#the-select option[value=1]");
    });
//]]>
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.