Changes

Jump to: navigation, search

JavaScript Document Object

746 bytes added, 20:51, 14 May 2007
Getting a list of objects in a document
=== Getting a list of objects in a document ===
A typical web page can contain a number of other object types, such as links, anchors, images and Java applets. A number of the proerties listed in the table above consist of arrays containing a list of objects of a particular type (for details on arrays see [[JavaScript Arrays]]) which can be accessed to get a list of objects present in a document. For example the ''links'' property can be used to obtain a list of Link objects in the current document: <pre> <html><head><title>JavaScript Document Object Example</title></head> <body><p>Sample text to show color change</p><a href="http://www.amazon.com">Buy more books</a><a href="http://www.yahoo.com">Stop making Google rich</a> for (i in document.links){ document.write( document.links[i] + "<br>" );}</script> </form></body></html> </pre> As one might expect the JavaScript in the above HTMl file outputs the following for the two links found in the document: <pre> http://www.amazon.com/http://www.yahoo.com/ </pre>

Navigation menu