Append to Select list

Posted on 2013-06-12
Last Modified: 2013-11-06

I want to append items to a select list including the option group how would I do this with the sample data below.

Group Fruit
Group Veg
Question by:JoeBo747
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 250 total points
ID: 39242176
LVL 11

Accepted Solution

SANDY_SK earned 250 total points
ID: 39309621
Something like this

<script type="text/javascript" src=""></script>

	$('<optGroup/>').attr('label', 'Group Fruit').appendTo($("#sampleSel"));
	$("#sampleSel").find('optGroup').last().append('<option value=11>Apple</option>');
	$("#sampleSel").find('optGroup').last().append('<option value=12>Orange</option>');
	$("#sampleSel").find('optGroup').last().append('<option value=13>Banana</option>');
	$('<optGroup/>').attr('label', 'Group Veg').appendTo($("#sampleSel"));
	$("#sampleSel").find('optGroup').last().append('<option value=21>Pea</option>');
	$("#sampleSel").find('optGroup').last().append('<option value=22>Cabbage</option>');
	$("#sampleSel").find('optGroup').last().append('<option value=23>Potato</option>');


<select id='sampleSel'>

Open in new window


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question