June 25, 2000 - The namespaces Collection
June 25, 2000 The namespaces Collection Tips: June 2000
Yehuda Shiran, Ph.D.
|
document
object. The collection itself is an array object:
oNameSpaceArray = document.namespaces;
To get to a particular namespace object, you can use simple indexing:
oNameSpace = document.namespace[index];
where index
starts from 0. You can use string indexing as well. If two namespaces have the same ID
or NAME
, another integer differentiator is needed:
oNameSpace = document.namespace(sIndex, iSecondary);
The following example uses two namespaces, DOCJS
and WEBREF
. When we call document.namespace(0)
from within the script below, we get the first namespace, DOCJS
, as expected.
<HTML XMLNS:DOCJS XMLNS:WEBREF>
<HEAD>
<STYLE>
@media all {
DOCJS\:RIGHT {text-align:right; width:100}
}
</STYLE>
</HEAD>
<BODY>
<DOCJS:RIGHT>
Read Doc JavaScript's columns, tips, tools, and tutorials
</DOCJS:RIGHT>
<SCRIPT>
a1 = document.namespaces(0);
alert(a1.name);
</SCRIPT>
</BODY>
</HTML>