jquery: how to append elements to empty object
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 do开发者_StackOverflow社区esn't work
var options = $('');
options.append('<option></option>')
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.
精彩评论