What is the dojo/dom-prop class?
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.
The dojo/dom-prop class
The 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 method
The get method can be used to get the value of a specific property of the DOM node.
Syntax
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.
Example
Explanation
In the above code:
Line 6: We have created a
divelement withidasparent.Line 7: We load the
dojolibrary from the CDN server.Line 9: We load the
dojo/dom-propmodule that contains thegetandsetmethod.Line 11: We use the
getmethod of thedom-propto get theinnerHTMLproperty of the element with idparent. We will get theinnerHTMLproperty as return value.
set method
The set method can be used to set the value of specific or multiple properties of the DOM node.
Syntax
We can call this method with two signatures.
Signature 1
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.
Signature 2:
set(idOrNodeElem, propertiesObject);
idOrNodeElem: The id of the DOM node or the DOM node itself.propertiesObject: The property name value object.
Example
Let's look at the code below:
Explanation
In the above code:
Line 6: We have created a
divelement withidasparent.Line 7: We load the
dojolibrary from the CDN server.Line 9: We load the
dojo/dom-propmodule that contains thegetandsetmethod.Line 15: We use the
setmethod of thedom-propto set the class property of the element with the idparent. This will set theclassproperty of the parent element asnew-class-1.Line 20: We use the
setmethod of thedom-propto set the properties(classandinnetHTML) of the element with the idparent. Here we pass the properties as an object. This will change theclassproperty tonew-class-2and theinnerHTMLproperty asnew content.
Free Resources