javaScript document object properties methods

the document object can be used to manipulate the html document within a window or frame.

the document object hold a complete html document which loaded into a web browser.

the document object is the root node of the html document and the 'owner' of all other nodes (element node, text node, attribute node etc.)

JavaScript document object properties

the document object provide the rich set of properties that can use for access html document information and set the document properties.



the following properties can be used on html documents

activeElementreturns the currently focused element
bodyreturns the <body> element of the document
characterSetreturns the character set being used by the document
cookiesets or gets the string value of a cookie
defaultViewreturns a reference to the window object
doctypereturns the document type definition(dtd) of the current document
documentElementreturns the root node of the document (the <html> element)
documentModereturns the mode used by the browser to render the document
documenturisets or returns the location of the document
domainreturns the domain name of the server that loaded the document
headreturns the head element of the document
implementationreturns the implementation object of the current document
inputEncodingreturns the character encoding, used for the document
readyStatereturns the loading status of the document
referrerreturns the url of the document that loaded the current document
lastModifiedreturns date and time the document was last modified
readyStatereturns a value that indicates the current state of the object
titlesets or returns the title of the document
urlreturns the full url of the document
collection propertydescription
anchors[]returns a collection of all the anchors(<a>) in the document
applets[]returns a collection of all applet objects in the document
embeds[]returns a collection of all the embedded objects in the document
forms[]returns a collection of all the forms in the document
images[]returns a collection of all the images(<img>) in the document
links[]returns a collection of all the links(<a>) in the document
plugins[]returns a list of the available plugins
styleSheets[]returns a list of the stylesheet objects on the current document
scripts[]returns all the <script> elements on the document

JavaScript document object methods

the following methods can be used on to html document

adoptNode(node)returns an adapded node from another document to this document
addEventListenerregisters an event handler for the specified event type
close()closes an output stream and forces the sent data to display
createAttribute()creates an attribute node
createComment()creates an comment node with a specified text
createcdatasection()creates a cdata section that contains the specified text
createDocumentFragment()creates a new document
createElement()creates an element node
createTextNode()Creates a text node
createNodeIterator()creates a NodeIterator object
createRange()creates a range object
createTreeWalkercreates a treeWalker object
focus()Object gains focus
getElementById()returns the element that has the id attribute with the specified value
getElementsByName()accesses all elements with a specified name
getElementsByTagName()returns a NodeList containing all elements with the specific tagname
hasFocus()returns true/false value indicating whether the object currently has focus
importNode()returns a clone of a node from an external document
normalize()removes empty text nodes, and joins adjacent nodes
open()opens an html output stream to collect output from document.write()
querySelector()returns first element node within the document that match the specified selectors
querySelectorAll()returns a list of all the element nodes within the document that match the specified selectors
removeEventListener()removes an event that the addEventListener method registered
write()writes html expressions or js code to a document
writeln()same as write() method but adds a newline character after each statement