Dave's Brain

Browse - Programming Tips - What's the best way to append an option to a select with jQuery?

Date: 2011dec8
Platform: web
Libary: jQuery
Language: javaScript

Q.  What's the best way to append an <option> to a <select> with jQuery?

A.  This function does it

function selectAppend(jquerySearch, myvalue, pretty) { $(jquerySearch).append($('<option>', { value : myvalue }).text(pretty)); }
Example use:
selectAppend('#myselect', '1.00', 'One Dollar');

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.