DHTML Methods
DOM Level 1 Specification.
Adds an element to a collection.
object.add ( oElement [ , iIndex ] )
oElement |
Required. Element object to add. |
iIndex |
Optional. Index position in the collection where the element will be placed. If no value is given, the method places the element at the end of the collection. |
No return value.
This method is the equivalent of the appendChild method of the node interface if the before parameter is null. It is equivalent to the insertBefore method on the parent of before in all other cases.
Before an element can be added to a collection, it must first be created using the createElement method.
For a SELECT object, this method adds a new element to the collection of OPTION elements in the SELECT.
For the areas object, this method can only be used on the object after the page has been loaded. If the method is applied inline, a run-time error will occur.
This example adds entries to a SELECT list when a user double-clicks on the entry field.
<head>
<script language="JavaScript">
function addItem ( ) {
sNewItem = new Option ( txtEnter.value )
selList.add ( sNewItem, -1 );
}
</script>
</head>
<body>
<input type="text" name="txtEnter" value="Enter text"
ondblclick="addItem ( )">
<select name="selList"></select>
</body>
Show me
areas, controlRange, options
remove