tags:

views:

152

answers:

1

In ASP C#, you can create a select (ListBox) then populate it with items (ListItem): ListBox1.Items.Add( new ListItem("Display name", "value")); This has an Add method that takes a ListItem option object.

Is there something similar in JQuery where you can add JavaScript objects to JQuery selected DOM objects without using ad hoc html text?

Dumb question but I wanted to make sure I wasn't completely missing something to add JavaScript variables that are DOM elements to JQuery selected items.

+2  A: 
var opt = document.createElement('option');
opt.appendChild(document.createTextNode('test'));
$('select').append(opt);

Works for me (I tested in IE 6, Firefox 3 and Safari 4).

eyelidlessness
Now that is fantastic!
Dr. Zim