Dojo: How to get the ID of an element.

To get the ID of an element using Dojo Framework, you need to use the dojo.attr function.

Given the following HTML:

<img src="/path/to/imageA.jpg" id="myImage1" />
<img src="/path/to/imageB.jpg" id="myImage2" />
<img src="/path/to/imageC.jpg" id="myImage3" />

You can get the IDs of each image in Dojo like so:

dojo.query("img").forEach(function(currentNode) {
    var theElementId = dojo.attr(currentNode, "id");
    console.log("id: ", theElementId); // debug
});

If you have debugging on and something like Firebug, the console output would be like so:

id: myImage1
id: myImage2
id: myImage3