Dave's Brain

Browse - programming tips - jquery append to select

Date: 2011dec8
Platform: jQuery
Language: javaScript

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

A.  I use this function:

	function selectAppend(jquerySearch, myvalue, pretty) {
		$(jquerySearch).append($('<option>', { value : myvalue }).text(pretty)); 
	}

	example use:

	selectAppend('#myselect', '1.00', 'One Dollar');
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: