Dynamic HTML FAQ Page
Listed below are some of the most commonly asked questions pertaining to DHTML.const unsigned short ELEMENT_NODE = 1; const unsigned short ATTRIBUTE_NODE = 2; const unsigned short TEXT_NODE = 3; const unsigned short CDATA_SECTION_NODE = 4; const unsigned short ENTITY_REFERENCE_NODE = 5; const unsigned short ENTITY_NODE = 6; const unsigned short PROCESSING_INSTRUCTION_NODE = 7; const unsigned short COMMENT_NODE = 8; const unsigned short DOCUMENT_NODE = 9; const unsigned short DOCUMENT_TYPE_NODE = 10; const unsigned short DOCUMENT_FRAGMENT_NODE = 11; const unsigned short NOTATION_NODE = 12;These are scriptable in NN6 as static properties of the Node object e.g.
Node.ELEMENT_NODE Node.ATTRIBUTE_NODEUnfortunately, IE5 does not expose the Node object or its static properties. With IE5, you are forced to hard code the constants' values.
iType = oNode.nodeTypewhere iType specifies an integer (as shown in the above table) indicating the nodeType of the requested node, which also determines the valid values for the node, and whether the node can have child nodes. The property is read-only.
document.getElementsByTagName('META')
Here is a link to a complete example reading the <META NAME="keywords" ...> elements' content values into an array:Demo: Reading META tag keywords.
For browsers not supporting the META element access an empty array is returned.
var allTables = document.all ?
document.all.tags('TABLE') :
document.getElementsByTagName ?
document.getElementsByTagName('TABLE') : new Array();
Then you can loop through allTables. If you just want to access a particular table, then give it an ID attribute like below:
var table = document.all ? document.all['aTable'] :
document.getElementById ?
document.getElementById('aTable') : null;
if (table)
// script table for instance loop through table.rows
Demo: Dynamically add elements to forms.
NN4 will not allow dynamic addition or removal of form fields unless you keep the whole form as a js data structure which you dynamically write to a layer. IE4 allows the insertion of unparsed html but is rather weak in removing elements. I might add an IE4 example later.
<STYLE>
#elementID {
property-name: propertyValue;
}
</STYLE>
Then with NN4 you can read document.ids['elementID'].propertyName while with IE4+ and NN6 you have to search through document.styleSheets and the rules to find the matching selector and access the style info.Demo: Reading styles of an ID selector rule.
<STYLE>
.styleClass {
property-name: propertyValue;
}
</STYLE>
Then with NN4, you can read document.classes['styleClass'].all while with NN6 and IE4+ you have to loop through document.styleSheets to find the matching style rule.Demo: Reading CLASS styles.
form.elements[0] window.frames['frameName'] document.styleSheets['styleSheetId']Internet Explorer 5.0 and later:
var nbsp = document.createTextNode( "\u00A0" ); referenceToWhereYouWantIt.appendChild( nbsp );
Demo: Adding sub-sections to collapse menus.
Demo: Expand acronyms and abbreviations.