Stands for “Document Object Model.”

The DOM is a programming interface for accessing and modifying the content material of webpages and XML paperwork. It defines the logical construction of a doc, treating it like a tree the place every branching node represents particular person components. Programs and scripts can entry the DOM to learn and modify the doc’s construction, content material, and magnificence.

The DOM organizes the construction of HTML and XML recordsdata in a hierarchy of objects known as “nodes.” At the basis is the Document node, which represents the doc as a complete. Next are the Element nodes that signify particular person HTML or XML tags. Element nodes are themselves hierarchical in the best way that they are nested. For instance, the <html> node is closest to the basis of the doc and incorporates each the <head> and <physique> nodes, and every of these incorporates baby nodes like <div> and <p> components.

Each ingredient node within the DOM contains a number of Attribute nodes that modify its properties. For instance, an <img> ingredient node might embrace attribute nodes for src, alt, width, and top that will enable some JavaScript to switch any of these attributes. Finally, Text nodes comprise the textual content inside every ingredient, making up the doc contents. Text nodes are the leaves of the tree and don’t have any additional ranges after them.

The DOM hierarchy showing several elements and how they relate to each other
The DOM hierarchy exhibiting a number of components and the way they relate to one another

Using JavaScript (or different scripting languages) to entry a web page’s DOM permits you to create dynamic and interactive webpages. For instance, occasion handlers connected to nodes can anticipate person interactions like mouse clicks or keyboard enter, then modify the web page contents in response. JavaScript occasions can use the DOM to take away present nodes and add new ones. Scripts can fetch knowledge from a database on a server and use the DOM to insert that knowledge into particular textual content components. Scripts may also use the DOM to switch the CSS properties of components and alter the doc’s look and structure.

Looking to know more Internet Terms