Nowadays, most people use libraries and frameworks in order to manipulate the web page. However, no matter how helpful and sophisticated the library, you still need to have a good idea of what you can, and cannot, do to the web page before making effective use of a library. More importantly, you need to have a good idea of the best practices to use when modifying the web page.
Accessing a Given Element and Finding Its Parent and Child Elements
You want to access a specific web page element, and then find its parent and child elements.
Give the element a unique identifier:
<p>This is text.
document.getElementById() to get a reference to the specific element:
Find its parent via the
Find its children via the
A web document is organized like an upside-down tree, with the topmost element at the root and all other elements branching out beneath. Except for the root element (HTML), each element has a parent
node, and all of the elements are accessible via the
There are several different techniques available ...