javascript options add( )
add( ) | Firefox/Netscape/NN n/a IE 4 Chrome/Safari/DOM n/a |
add(elementRef[, index]) | |
Adds an already-created element (from the createElement( ) method) to the current collection. The element must be of the option type. By default, the new element is added as the last item of the collection unless you specify an index value as a second parameter (in which case all existing items from that index position get pushed down by one). The following example sequence appends a new item to a select object: var newElem = document.createElement("option"); newElem.text = "Freddy"; newElem.value = "Freddy Mercury"; document.forms[1].rockers.options.add(newElem); |
|
Notice that a generic object is created first. Then its properties are stuffed with values, and the new element is added to the select element. |
|
For an example of a cross-browser and backward-compatible approach to this task, see the option object discussion. Also see the select.add( ) method for a W3C DOM approach that works with Netscape 6. |
|
Parameters | |
|
|
Returned Value | |
None. |
Powered by Linode.