HTML DOM Examples
Examples of HTML DOM objects accessed and manipulated using JavaScript.
Document Object
- Use document.write() to output text
- Use document.write() to output HTML
- Return the number of anchors in a document
- Return the innerHTML of the first anchor in a document
- Return the number of forms in a document
- Return the name of the first form in a document
- Return the number of images in a document
- Return the ID of the first image in a document
- Return the number of links in a document
- Return the ID of the first link in a document
- Return the name/value pairs of all cookies in a document
- Return the server domain name of the loaded document
- Return the last modified date of a document
- Return the URL of the currently loaded document
- Return the title of a document
- Return the full URL of a document
- Open an output stream and write text to the stream
- The difference between write() and writeln()
- Pop up the innerHTML of an element with a specified ID
- Pop up the number of elements with a specified name
- Pop up the number of elements with a specified tag name
- More Document object examples, in ourJavaScript Reference Manual.
Anchor Object
- Return and set the charset attribute of a link
- Return and set the href attribute of a link
- Return and set the hreflang attribute of a link
- Return the name of an anchor
- Return the relationship between the current document and the linked document
- Change the target attribute of a link
- Return the value of the type attribute of a link
- More Anchor object examples, in ourJavaScript Reference Manual.
Area Object
- Return the alternative text of a certain area of an image map
- Return the coordinates of a certain area of an image map
- Return the anchor part of the href attribute of an area
- Return the hostname and port of a certain area of an image map
- Return the hostname of a certain area of an image map
- Return the port of a certain area of an image map
- Return the href of a certain area of an image map
- Return the pathname of a certain area of an image map
- Return the protocol of a certain area of an image map
- Return the querystring part of the href attribute of an area
- Return the shape of a certain area of an image map
- Return the value of the target of a certain area of an image map
- More Area object examples, in ourJavaScript Reference Manual.
Base Object
- Return the root URL of all relative URLs on the page, that is, the href attribute value of the base tag.
- Return the opening method corresponding to the root URL of all relative URLs on the page, that is, the target attribute value of the base tag.
- More Base object examples, in ourJavaScript Reference Manual.
Button Object
- Make the button unavailable after clicking
- Return the name of a button
- Return the type of a button
- Return the value of a button
- Return the ID of the form to which a button belongs
- More Button object examples in ourJavaScript Reference Manual.
Form Object
- Return the value of all elements in a form
- Return the value of the acceptCharset attribute of a form
- Return the value of the action attribute of a form
- Return the value of the enctype attribute in a form
- Return the number of elements in a form
- Return the method for sending form data
- Return the name of a form
- Return the value of the target attribute of a form
- Reset a form
- Submit a form
- More Button object examples in ourJavaScript Reference Manual.
Frame/IFrame Object
- Align an iframe
- Change the background color of a document contained in an iframe
- Return the value of the frameborder attribute in an iframe
- Remove the frameborder of an iframe
- Change the height and width of an iframe
- Return the value of the longdesc attribute in an iframe
- Return the value of the marginheight attribute in an iframe
- Return the value of the marginwidth attribute in an iframe
- Return the value of the name attribute in an iframe
- Return and set the value of the scrolling attribute in an iframe
- Change the src of an iframe
- More Frame/IFrame object examples in ourJavaScript Reference Manual.
Image Object
- Align an image
- Return the alternative text of an image
- Add a border to an image
- Change the height and width of an image
- Set the hspace and vspace attributes of an image
- Return the value of the longdesc attribute of an image
- Create a link pointing to a low-resolution image
- Return the name of an image
- Change the src of an image
- Return the value of the usemap of a client-side image map
- More Image object examples in ourJavaScript Reference Manual.
Event Object
- Which mouse button was clicked?
- What is the keycode of the pressed keyboard key?
- What are the coordinates of the mouse?
- What are the coordinates of the mouse relative to the screen?
- Was the Shift key pressed?
- Which element was clicked?
- Which event occurred?
Option and Select Objects
- Disable and enable a dropdown list
- Get the ID of the form containing a dropdown list
- Get the number of options in a dropdown list
- Turn a dropdown list into a multiline list
- Select multiple options in a dropdown list
- Pop up all options in a dropdown list
- Pop up the index of the selected option in a dropdown list
- Change the text of the selected option in a dropdown list
- Remove options from a dropdown list
Table, TableHeader, TableRow, TableData Objects
- Change the border width of a table
- Change the cellpadding and cellspacing of a table
- Specify the frame of a table
- Specify rules for a table
- The innerHTML of a row
- The innerHTML of a cell
- Create a caption for a table
- Remove rows from a table
- Add rows to a table
- Add cells to a table row
- Horizontally align the content of cells
- Vertically align the content of cells
- Horizontally align the content of a single cell
- Vertically align the content of a single cell
- Change the content of a cell
- Change the number of columns a cell spans (colspan attribute)