Select your language

Sign up

The DOM (Document Object Model) represents a document as a tree of nodes. Joomla JavaScript uses it to work with menus, forms, modules and dynamically updated content.

DOM and source HTML

The browser builds the tree from received markup. Scripts can then add or remove elements and change attributes or text. The current DOM may therefore differ from the server's original HTML response.

The DOM is not the JavaScript language itself. It provides an interface to the document. Scripts use its methods to locate elements, handle events and update page state.

Joomla practice

A Joomla template script must account for when the required element becomes available. After an AJAX update, references to removed nodes can become stale and event handlers may need appropriate reinitialisation.

When displaying external data in the Joomla DOM, use safe text handling. Assigning unchecked HTML through innerHTML can introduce XSS. Diagnose problems by comparing the original response, the Elements tree and console errors.

Conclusion

The DOM describes the document's current state. Understanding changes helps diagnose dynamic interfaces and update content safely.

Mentions:

JavaScript

Newsletter Subscription
Enter your email address and we will keep you updated!

Joomla.center is not affiliated with or endorsed by the Joomla!® Project or Open Source Matters. The Joomla!® name and logo is used under a limited license granted by Open Source Matters, the trademark holder in the United States and other countries.