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:

Property USES
document.anchors To get all the <a> elements that have a name attribute.
document.baseURI To get the absolute base URI of the document.
document.body To get the <body> element.
document.cookie To get the document’s cookie.
document.doctype To get the document’s doctype.
document.documentElement To get the <html> element.
 document.documentMode To get the mode used by the browser.
document.documentURI To get the URI of the document.
document.domain To get the domain name of the document server.
document.embeds To get all the <embed> elements.
document.forms To get all the <form> elements.
document.head To get the <head> element
document.images To get all the <img> elements.
document.implementation To get the DOM implementation.
document.inputEncoding To get the document’s encoding (character set).
document.lastModified To 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.readyState To get the (loading) status of the document.
document.referrer To get the URI of the referrer (the linking document).
document.scripts To get all the <script> elements.
document.strictErrorChecking To get if error checking is enforced.
document.title To get the <title> element.
document.URL To get the complete URL of the document.



Please Share