asp.net.ph

Skip Navigation Links

add Method

DHTML Methods


DOM Level 1 Specification.

Adds an element to a collection.

Syntax

object.add ( oElement [ , iIndex ] ) 
Parameters

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.

Return Value

No return value.

Remarks

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.

Example

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 

Applies To

areas, controlRange, options

See Also

remove



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note