YouTip LogoYouTip

Met Select Add

# Select add() Method [![Image 9: Select Object Reference](#) Select Object](#) * * * ## Definition and Usage The add() method is used to add an element to a . ## Syntax selectObject.add(_option,before_) | Parameter | Description | | :--- | :--- | | _option_ | Required. The option element to add. Must be an option or optgroup element. | | _before_ | Required. The element in the options array before which the new element should be added. If this parameter is null, the element is added to the end of the options array. | * * * ## Browser Support ![Image 10: Internet Explorer](#)![Image 11: Firefox](#)![Image 12: Opera](#)![Image 13: Google Chrome](#)![Image 14: Safari](#) The add() method is supported in all major browsers. **Note:** The add() method requires a !DOCTYPE declaration in the page for IE8 and higher versions of IE. * * * ## Example ## Example The following example adds a "kiwi" option to the end of the dropdown list: function displayResult(){ var x=document.getElementById("mySelect"); var option=document.createElement("option"); option.text="Kiwi"; try{ // For earlier versions of IE8 x.add(option,x.options); }catch (e){ x.add(option,null); } } Apple Pear Banana Orange

Note: The add() method works correctly in IE8 or higher versions. To add a !DOCTYPE declaration in the page. For versions before IE 8, note the additional code.

[Try it Yourself Β»](#) * * * ![Image 15: Example](#) ## More Examples (#) * * Select Object](#)
← Met Select RemoveProp Select Type β†’