tags:

views:

32

answers:

1

I want to create a set of options, that will be appended to every select in grid column

<option> option 1 </option>
<option> option 2 </option>
...
<option> option N </option>

but I don't know how to create a set of elements without parent element.

appending to an empty jquery object doesn't work

var options = $('');
options.append('<option></option>')
+2  A: 
var Select = $("body").append("<select><option>...</select>");
//if you don't want that select, remove it. But it could feasibly be your first select added to the page
Select = $("body").remove(Select);
var Options = Select.find("option");

Per you comment you might want to use the

$('select.selectClass').replaceWith(Select);

This will allow you to stick with a parent element.

aepheus
+1: I deleted my answer since I ended up modifying mine to suit your suggestion.
CAbbott
:) I was about to comment on the difference between .html() and .append() and the questions disappeared...
aepheus
@Mahesh Velaga append is a += html is just =. i.e. html will overwrite existing content.
aepheus
I meant to ask the other angle of it, I mean will .html() also create the dom for it automatically ?If I write .html("some html"), will it create DOM elements in the "some html" part? Thanks
Mahesh Velaga
for that matter will .append() or .html() create the dom elements of the passed in strings (if the string has some html tags in it)?
Mahesh Velaga
@Mahesh Velaga correct. append does the same when passed a string.
aepheus