Dominator.js | Nesting - Summary of Properties

A modern approach to DOM manipulation using Dominator Nesting

Summary of Dominator.js Properties (Nesting)

Dominator.js simplifies DOM manipulation by providing a set of properties that allow developers to create, style, and manipulate elements in a clean and intuitive way. These properties can be used for nesting elements inside one another, making the process more efficient.

Key Properties for Nesting:

1. element

The element property is used to define the type of the element to be created (e.g., div, p, span, etc.).

2. text

The text property is used to set the inner text of the created element.

3. html

The html property is used to set the inner HTML content of the element, allowing you to insert HTML tags inside the element.

4. child

The child property is used to define nested elements within the parent. It can be an object with properties like element, text, and css, or a function that gives developers the flexibility to define children dynamically based on the parent element.

5. children

The children property allows you to define multiple child elements in an array format, which can be either objects or functions.

6. on

The on property is used to attach event listeners to the element. It supports multiple events, where each event has a type (e.g., click), a callback function, and optionally data to pass additional information.

7. attr

The attr property is used to set one or more attributes for the element. It takes an object where the keys are attribute names, and the values are the attribute values.

8. css

The css property is used to apply CSS styles directly to the element. You can set multiple styles as an object, with the property names being CSS properties and the values being the corresponding styles.

9. appendTo

The appendTo property defines where the created element will be appended. It can be a string query (e.g., 'div.example-output') or an HTML element (e.g., document.querySelector('.example-output')).

10. prependTo

The prependTo property defines where the created element will be prepended, i.e., inserted as the first child of the target element.

11. before

The before property places the created element before the target element in the DOM. It accepts a string query or an HTML element as the target.

12. after

The after property places the created element after the target element in the DOM. It works similarly to before, but appends the element after the target.

13. fillTarget

The fillTarget property fills the created element into a target element, replacing its existing content.

14. replaceTarget

The replaceTarget property replaces the target element with the newly created element.

15. group

The group property allows you to group multiple elements together under a common identifier or selector. This can be useful for applying the same properties or methods to a collection of elements at once, improving the efficiency of your DOM manipulations.

Conclusion

Dominator.js offers a variety of properties that make DOM manipulation easier and more intuitive. By using properties such as element, text, css, on, and more, developers can create and manage DOM structures efficiently, all while taking advantage of the power of nesting to build complex elements in a concise and readable way.