Standard Methods
All of the following methods are specific to Internet Explorer 4.0's Dynamic HTML object model. None are supported by Netscape or any previous versions of Internet Explorer
click
The click
method can be used to 'click' a referenced object through scripting, forcing an onClick
event for the particular element. For example, click the top of the following two links and it 'clicks' the second link:
contains
The contains
method can be used to determine whether the referenced element totally encloses (contains) another element. For example:
<P ID="para1">Some <STRONG ID="str1">strong, bold</STRONG> text</P>
alert (para1.contains(str1))
would return true.
getAttribute
the getAttribute
method can be used to retrieve the value of a specific attribute for the referenced element. For example:
varCol=document.all.MySpan.getAttribute("BGCOLOR",false)
would retrieve the value of the BGCOLOR
attribute of the element whose ID
is MySpan
. The false
argument is a boolean value (i.e. true or false), specifying whether or not the search to find the attribute is case-sensitive or not. 'True' means that the attribute case must match that give in the attribute value, for the getAttribute
method to work - the default value is 'false'. Depending on the value of the attribute, the getAttribute
method returns either a string, a number, or a variant.
insertAdjacentHTML
The insertAdjacentHTML
method can be used to insert a new HTML element into the document, without removing a previous one (as manipulation of the innerHTML
and outerHTML
Properties insertAdjacentHTML
places the string specified in the second argument, at the position specified in the first argument. For example:
document.all.tags("P").item(1).insertAdjacentHTML("BeforeBegin", "<P>Here's a new paragraph")
would add <P>Here's a new paragraph
before the second paragraph in the document. The possible values for the positioning are:
BeforeBegin
AfterBegin
BeforeEnd
AfterEnd
insertAdjacentText
The insertAdjacentText
method is essentially identical to the insertAdjacentHTML
method, except that it inserts literal text, regardless of the strings actual content. It takes the same argument set - i.e. (string, position)
where position
can be one of the four values mentioned above.
removeAttribute
removeAttribute
can be used to remove an attribute and its associated value from the referenced element. This is subtly different to dynamically setting the attribute property value to nothing. Using the removeAttribute
value forces removal of the attribute, as if it had never been set in the first place. The removeAttribute
method returns a boolean (i.e. true or false) value depending on whether the attribute was successfully removed or not. Its optional second argument is a boolean value, which specifies whether to use a case-sensitive search to locate the attribute to remove. For example:
bKilldataSrc=dataTable.removeAttribute "DATASRC", "false"
would make the bKilldataSrc
true or false, depending on whether the DATASRC
attribute was removed from the element referenced by dataTable
. The search is case-insensitive. The default value for the case-sensitivity argument, if none is given, is 'true'.
scrollIntoView
The scrollIntoView
method can be used to force the current viewing window to scroll to a referenced element object. It accepts a boolean argument (true or false) which determines whether the window should be scrolled so that the referenced element object is at the top (true) or bottom (false) of the window. For example, the button below will scroll the links given in the click
example, so that they're at the bottom of the viewing window.
setAttribute
Like the other *Attribute
methods, setAttribute
can be used to set the value of a specific attribute for a referenced element. For example:
MyTable.setAttribute "DATASRC", "#Comp1", true
would set the DATASRC
attribute to #Comp1
for the element referenced by MyTable
. Basically, the first and second arguments for the method specify the attribute and its value to be set, with the third argument being 'true' or 'false', specifying whether case sensitive setting of the attribute is used or not. If this is set to 'true' (the default) and the attribute name you specify for the referenced element has a different case than any existing setting of that attribute, then a new attribute will be created, with the value specified in the value argument.
© 1995-1998, Stephen Le Hunte