Dojo is a JavaScript toolkit (library) that provides many utility modules and functions to create a web application. We can save time and speed up the development process using the predefined Dojo modules. Dojo includes language utilities, UI components, and more.
dojo/dom-prop classThe dojo/dom-prop module is a utility module to get and set the properties of the DOM node. It has two methods get and set.
get methodThe get method can be used to get the value of a specific property of the DOM node.
get(idOrNodeElem, propertyName);
This method takes two arguments
idOrNodeElem: The id of the DOM node or the DOM node itself.
propertyName : The name of the property to get.
In the above code:
Line 6: We have created a div element with id as parent.
Line 7: We load the dojo library from the CDN server.
Line 9: We load the dojo/dom-prop module that contains the get and set method.
Line 11: We use the get method of the dom-prop to get the innerHTML property of the element with id parent . We will get the innerHTML property as return value.
set method The set method can be used to set the value of specific or multiple properties of the DOM node.
We can call this method with two signatures.
set(idOrNodeElem, propertyName, value);
idOrNodeElem: The ID of the DOM node or the DOM node itself.
propertyName : The name of the property to get.
value : The value to be set for the property.
set(idOrNodeElem, propertiesObject);
idOrNodeElem: The id of the DOM node or the DOM node itself.
propertiesObject: The property name value object.
Let's look at the code below:
In the above code:
Line 6: We have created a div element with id as parent.
Line 7: We load the dojo library from the CDN server.
Line 9: We load the dojo/dom-prop module that contains the get and set method.
Line 15: We use the set method of the dom-prop to set the class property of the element with the id parent . This will set the class property of the parent element as new-class-1.
Line 20: We use the set method of the dom-prop to set the properties(class and innetHTML) of the element with the id parent . Here we pass the properties as an object. This will change the class property to new-class-2 and the innerHTML property as new content.
Free Resources