JavaScript Object Examples
Examples using built-in JavaScript objects.
Document Object
- Output text using document.write()
- Output HTML using document.write()
- Return the number of anchors in the document
- Return the innerHTML of the first anchor in the document
- Return the number of forms in the document
- Return the name of the first form in the document
- Return the number of images in the document
- Return the ID of the first image in the document
- Return the number of links in the document
- Return the ID of the first link in the document
- Return all cookie name/value pairs in the document
- Return the server domain name of the loaded document
- Return the last modified date of the document
- Return the URL of the currently loaded document
- Return the title of the document
- Return the full URL of the document
- Open an output stream and write text to it
- 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 examples of Document objects, in ourJavaScript Reference Manual.
Anchor Object
- Return and set the charset property of a link
- Return and set the href property of a link
- Return and set the hreflang property of a link
- Return the name of an anchor
- Return the relationship between the current file and the linked document
- Change the target property of a link
- Return the value of the type property of a link
- More examples of Anchor objects, in ourJavaScript Reference Manual.
Area Object
- Return the alternate text of an area in an image map
- Return the coordinates of an area in an image map
- Return the anchor part of the href property of an area
- Return the host name: the port of an area in an image map
- Return the hostname of an area in an image map
- Return the port of an area in an image map
- Return the href of an area in an image map
- Return the pathname of an area in an image map
- Return the protocol of an area in an image map
- Return the query string part of the href property of an area
- Return the shape of an area in an image map
- Return the value of the target of an area in an image map
- More examples of the Area object are in ourJavaScript Reference Manual.
Base Object
- Return the base URL of all relative URLs on the page
- Return the base link of all relative links on the page
- More examples of the Base object are in ourJavaScript Reference Manual.
Button Object
- When clicked, the button becomes disabled
- Return the name of a button
- Return the type of a button
- Return the value of a button
- Return the ID of the form a button belongs to
- More Button object examples are in ourJavaScript Reference Manual.
Form Object
- Return the value of all elements in a form
- Return the value of the acceptCharset property of a form
- Return the value of the action property of a form
- Return the value of the enctype property of a form
- Return the number of elements in a form
- Return the method used to send form data
- Return the name of a form
- Return the value of the target property of a form
- Reset the form
- Submitting a Form
- More Form object examples in ourJavaScript Reference Manual.
Frame/IFrame Object
- Layout the iframe
- Change the background color of a document contained in an iframe
- Return the value of the frameborder property of an iframe
- Remove the frameborder of an iframe
- Change the height and width of an iframe
- Return the value of the longdesc property of an iframe
- Return the value of the marginheight property of an iframe
- Return the value of the marginwidth property of an iframe
- Return the value of the name property of an iframe
- Return and set the value of the scrolling property of an iframe
- Change the src of an iframe
- More Frame/IFrame object examples in ourJavaScript Reference Manual.
Image Object
- Layout the image
- Return the alternate text of an image
- Add a border to an image
- Change the height and width of an image
- Set the hspace and vspace properties of an image
- Return the value of the longdesc property 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
- The keyCode of the pressed keyboard key?
- The coordinates of the mouse?
- The coordinates of the mouse relative to the screen?
- Was the shift key pressed?
- Which event occurred?
Option and Select Objects
- Disable and enable a drop-down list
- Get the ID of the form that has the drop-down list
- Get the number of options in the drop-down list
- Turn the drop-down list into a multi-line list
- Select multiple options in the drop-down list
- Pop up the selected option in a drop-down list
- Pop up the index of the selected option in the drop-down list
- Change the text of the selected option in the drop-down list
- Remove an option from the drop-down list
Table, TableHeader, TableRow, TableData Objects
- Change the width of a table border
- 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
- Delete a row from a table
- Add a row to a table
- Add a cell to a table row
- Horizontally align cell content
- Vertically align cell content
- Horizontally align the content of a single cell
- Vertically align the content of a single cell
- Change the content of a cell
- Change the content of a line