Trying to access the options of a dropdown box using jQuery/javascript, but it's saying that .options is undefined? -
I am dynamically creating a dropdown box by adding jQuery as follows:
  .append ("& lt; SELECT NAME = 'Month_list' class = 'month_selection' & lt; / SELECT & gt;");   This is made fine, but I'm trying to dynamically add options using the following code:
  $ ('month_selection : Last ') .options.add (new option (month_are [index]);   But I'm getting the following error in the firebug:
  $ (". Month_selection: last"). Options are undefined    The selector is working fine because I can run the line of code  $ ("month_selection: last"). Remove ()  and dropdown box is removed, and with it can I tell  .options  from various teutes how to use options, what am I doing wrong? Thanks for reading. 
 You  & lt; Select & gt;  DOM is required to access the element in such a way: 
  $ ('month_selection: last') [0]. Option // or ... $ ('month month_selection'). Get (-1) option   .
 For DOM properties, you first need to get the DOM element (through  [0]  or in this case)  then  your properties Use, otherwise you are trying to use the properties present on the jQuery object that does not exist. 
Comments
Post a Comment