Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is attribute.specified for a DOM element's attributes?

Tags:

dom

attributes

I just stumbled across something like this...

function(element) {
  ...
  var attributes = element.attributes;
  for (var index = 0, length = attributes.length; index < length; index++) {
    var attribute = attributes[index];

    // what is ".specified"?
    if (attribute.specified) {
      ...
    }
  }
}

I'm looking at the W3C specs for a DOM Element, the Element interface, and I don't see specified anywhere.

http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-745549614

What does attribute.specified mean? What does it represent? Where is it defined in the specs?

like image 391
Hristo Avatar asked Jan 23 '13 20:01

Hristo


1 Answers

<img src="kittens.jpg">. the attribute is src, and its value is kittens.jpg. DOM elements are generic definitions. the actual attributes are specified by the actual language being used, e.g. XML, HTML, etc....

specified = the attribute has an explicit value assigned to it. e.g. the src attribute is specified, because it's been given the value kittens.jpg, but

<input type="checkbox" checked />

the checked attribute is PRESENT, but not SPECIFIED.

like image 161
Marc B Avatar answered Oct 04 '22 21:10

Marc B