You should be aware that element.value
only works with elements where it's part of the DOM, defined by W3C. So, if you look at the HTMLInputElement
interface (used by form elements), you will see that it clearly has a property called value
, referencing to the the value of the element.
However, the same is not true for an HTMLAnchorElement. This means the proper way to retrieve the value of the value
attribute, is by selecting the attribute itself, using the getAttribute()
function or by using the the dojo/dom-attr Dojo module.
For example:
require(["dojo/query", "dojo/dom-attr", "dojo/domReady!"], function(query, domAttr) {
query("a").forEach(function(element) {
console.log(element.id);
console.log(domAttr.get(element, "value")); // This will work
});
});
Demonstration: JSFiddle