{"id":10573,"date":"2019-10-14T15:09:27","date_gmt":"2019-10-14T19:09:27","guid":{"rendered":"https:\/\/www.carnaghan.com\/?p=10573"},"modified":"2021-03-06T15:48:23","modified_gmt":"2021-03-06T20:48:23","slug":"javascript-manipulating-the-document-object-model-dom","status":"publish","type":"post","link":"https:\/\/www.carnaghan.com\/javascript-manipulating-the-document-object-model-dom\/","title":{"rendered":"JavaScript Manipulating the Document Object Model (DOM)"},"content":{"rendered":"\n

The way in which logical structure of a document is accessed and manipulated in HTML is known as Document Object Model or DOM. It is a programming interface for HTML. Whenever a document loads in the browser, a tree-like (or forest) structure is created. Methods provided by the DOM can be used to access and manipulate this tree programmatically.<\/p>\n\n\n\n

Why use DOM?<\/h2>\n\n\n\n

The DOM is used to access and manipulate elements in an HTML document. But why do we need to use the DOM for this? Let’s understand this by use of an example. Let’s suppose we have an input field and a button next to it. When the button is clicked, whatever typed in the input field should appear below the input field. How can we do this with plain HTML? We need to dynamically access the value of the input field on the button click and then display the value below in a paragraph. We will implement this example, but first, we should discuss DOM methods that will be needed for accessing and manipulating elements.<\/p>\n\n\n\n

Methods and\nproperties of DOM<\/h2>\n\n\n\n

There are three basic methods of DOM for\naccessing elements.<\/p>\n\n\n\n