Hi. I'm just getting started with jQuery and I'm still trying to figure out how to do some common tasks. Here's one of them.
Suppose I have something like: var opts = $( 'option', select ); ...where select is some <select> DOM element, and later I create a new option var o = document.createElement( 'option' ); Now, to add this new option element, I'd do something like this: $( select ).append( o ); and I'd have to update opts: opts = $( 'option', select ); For some reason I have the feeling that one should be able to do this more elegantly with jQuery, but I can't hit upon the right way to do it... What I mean is that opts already holds all the options in select. I'd like to add one more item to it, in a way that affects both the jQuery object *and* the context of the original query (i.e. the select element). At the very least I'd like to be able to append one item to the jQuery object, but I found that the following naive approach does not work: opts[ opts.length ] = o; Yes, the new item is added to the opts array, but it is not treated as part of the selection. And, of course, even if it did, the original select item would remain unchanged (i.e. o would not have been appended to it). I feel I'm missing something pretty fundamental here, and I'd appreciate any pointers you may have (especially to documentation). kynn