2014-04-29

jQuery adding options to a select list

From time to time I find myself searching for the same solution to something I know I've already done.  This is one of those things.  I needed to add options to a select list with jQuery.

In the code below lines one and four are the old manual way I did things.  If I needed the value or the text of the option to be a JavaScript variable, I had to start concatenating the strings.  This is a bit easier with lines two and five.

Also note, in the programmatic way if you need to insert HTML entities you have to use the html function instead of the text function.


No comments:

Post a Comment