javascript Document object

Document object

The javascript document object is the window property which is used to represent a web page or the html document. It is a property of window object and thus can be written as window.document or only document.


Methods of Document Object:

document.getElementById(id)To get an element by its element id.
document.getElementsByName(name)To get an element by its name.
document.getElementsByTagName(name)To get an element by its tag name.
document.getElementsByClassName(name)To get an element by its class name.
document.createElement(element)To create an HTML element
document.removeChild(element)To remove an HTML element
document.appendChild(element)To add an HTML element
document.replaceChild(element)To replace an HTML element
document.write(text)To write into the HTML output stream
document.getElementById(id).onclick = function(){code}To add an event handler code to an onclick event.


To write the given string on the document with newline character at the end.


Properties of Document Object:

document.anchorsTo get all the <a> elements that have a name attribute.
document.baseURITo get the absolute base URI of the document.
document.bodyTo get the <body> element.
document.cookieTo get the document’s cookie.
document.doctypeTo get the document’s doctype.
document.documentElementTo get the <html> element.
 document.documentModeTo get the mode used by the browser.
document.documentURITo get the URI of the document.
document.domainTo get the domain name of the document server.
document.embedsTo get all the <embed> elements.
document.formsTo get all the <form> elements.
document.headTo get the <head> element
document.imagesTo get all the <img> elements.
document.implementationTo get the DOM implementation.
document.inputEncodingTo get the document’s encoding (character set).
document.lastModifiedTo get the date and time the document was updated.
document.links To get all the <area> and <a> elements that have a href attribute.
document.readyStateTo get the (loading) status of the document.
document.referrerTo get the URI of the referrer (the linking document).
document.scriptsTo get all the <script> elements.
document.strictErrorCheckingTo get if error checking is enforced.
document.titleTo get the <title> element.
document.URLTo get the complete URL of the document.



Please Share