What attribute is specified for attributes of a DOM element?

I just stumbled upon 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 look at the W3C specifications for the DOM element, the Element interface, and I do not see specifiedanywhere.

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

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

+5
source share
3 answers

<img src="kittens.jpg">. attribute src, and its value kittens.jpg. DOM elements are common definitions. actual attributes are determined by the actual language used, for example. XML, HTML, etc.

specified = the attribute has an explicit value assigned to it. for example, the src attribute is specified, because it is assigned the value kittens.jpg, but

<input type="checkbox" checked />

PRESENT, .

+2

, < node specified IE 6-7, IE 6-7 attributes node. specified, , node. false, node , /. attributes , , , attribute.specified true . element.hasAttribute(attribute) , element.attributes[attribute].specified IE 6-7.

0

DOM , , . .

Chrome 54.0.2840.71, .specified true, DOM, , , . , __test Chrome ( 54).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div __test></div>
    <script>
        var div=document.querySelector("div");
        var attributes = div.attributes;
        var attr_test=attributes[0];
        attr_test.specified=false;// "specified" is not writable and Setting it silently fails.
        console.log(attr_test.specified);
    </script>
</body>
</html>

, " ".

"attribute.specified" DOM3 DOM2.

1.

, , false. node ( , ), true.

2.Differences
"DOM-Level2" , , "attribute.specified" .
"DOM-Level3"

An implementation can handle attributes with default values ​​from other schemas in a similar way, but applications should use Document.normalizeDocument () to ensure that this information is up to date.

search specified of type boolean, readonlyat
https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-637646024
versus
https://www.w3.org/TR/DOM-Level-2-Core/ core.html # ID-862529273

-1
source

All Articles