-
-
Notifications
You must be signed in to change notification settings - Fork 5
Document Object Model
The DOM repository is separately maintained at https://github.com/PhpGt/Dom
The Document Object Model (DOM) is an API understood by all web browsers that is used to represent the structure of HTML and XML documents, such as the pages within your application. It allows software to read from and manipulate the page at runtime, providing the basis for dynamic pages.
Tags within HTML such as <img> tags, <article> tags, and plain old <div> tags are represented in the DOM as Element objects, and provide mechanisms for reading and updating the elements contents, and traversing the DOM as a tree (nodes with parents, children and siblings).
<body>
<article>
<h1>Hello, World!</h1>
<p>This is just an example.</p>
<p>A simple HTML snippet.</p>
</article>
</body>In the above snippet of HTML, the tree is visualised by indentation. The <article> element has a parent, the <body> and three children, the <h1> and the two <p> elements. From any of the elements a program can traverse the whole tree.
The DOM exposes many useful functions to work with the Elements of the tree. As a brief example, it is possible to iterate over all the <p> elements in the page and change their text to uppercase by using the getElementsByTagName function as follows:
public function go() {
$paragraphList = $this->document->getElementsByTagName("p");
foreach($paragraphList as $paragraph) {
$paragraph->innerText = strtoupper($paragraph->innerText);
}
}- File-based routing
- Page views
- Page logic
- Dynamic URIs
- Headers and footers
- Custom HTML components
- Page partials
- Binding data to the DOM
- DOM manipulation
- Hello You tutorial
- Todo list tutorial
- Address book tutorial WIP
- Blueprints
- Application architecture
- Coding styleguide WIP
- PHP environment setup WIP
- Web servers WIP
- Background cron tasks
- Database setup WIP
- Client-side compilation WIP
- Testing WebEngine applications WIP
- Production checklist WIP
- Security WIP