51

While reading over the WHATWG's HTML5 - A technical specification for Web developers I see many references such as:

Reflecting content attributes in IDL attributes

Some IDL attributes are defined to reflect a particular content attribute. This means that on getting, the IDL attribute returns the current value of the content attribute, and on setting, the IDL attribute changes the value of the content attribute to the given value.

and:

In conforming documents, there is only one body element. The document.body IDL attribute provides scripts with easy access to a document's body element.

The body element exposes as event handler content attributes a number of the event handlers of the Window object. It also mirrors their event handler IDL attributes.

My (admittedly fuzzy) understanding comes from the Windows world. I think an .idl file is used to map remote procedure calls in an n-tier distributed app. I would assume a content attribute refers to html element attributes.

There is no place in the standard that I can see that explains this usage of the terms "content attribute" and "IDL attribute". Could anyone explain what these terms mean and how the two kinds of attributes relate?

Sinthia V
  • 2,103
  • 2
  • 18
  • 36
  • 1
    An example of an IDL attribute is `innerHTML` of an `Element`. When you set a value to this attribute, it triggers a change of the DOM after parsing the supplied value. It is very much unlike a content attribute. – HRJ Mar 18 '14 at 12:37

1 Answers1

67

The IDL (Interface Definition Language) comes from the Web IDL spec:

This document defines an interface definition language, Web IDL, that can be used to describe interfaces that are intended to be implemented in web browsers. Web IDL is an IDL variant with a number of features that allow the behavior of common script objects in the web platform to be specified more readily. How interfaces described with Web IDL correspond to constructs within ECMAScript execution environments is also detailed in this document.

Content attributes are the ones that appear in the markup:

<div id="mydiv" class="example"></div>

In the above code id and class are attributes. Usually a content attribute will have a corresponding IDL attribute.

For example, the following JavaScript:

document.getElementById('mydiv').className = 'example'

Is equivalent to setting the class content attribute.

In JavaScript texts, the IDL attributes are often referred to as properties because they are exposed as properties of DOM objects to JavaScript.

While there's usually a corresponding pair of a content attribute and an IDL attribute/property, they are not necessarily interchangeable. For example, for an <option> element:

  • the content attribute selected indicates the initial state of the option (and does not change when the user changes the option),
  • the property selected reflects the current state of the control
Jarrod Dixon
  • 15,727
  • 9
  • 60
  • 72
robertc
  • 74,533
  • 18
  • 193
  • 177
  • 1
    Thank you for the link to Web IDL. And this is supposed to be the "readable" version! – Sinthia V Sep 10 '12 at 16:01
  • So what about e.g. onclick and others? I read somewhere on Mozillas mailingslists that these are IDL attributes but they also appear in the markup... They described content attributes as the ones which affect the rendering process. – Florian Loch Jul 24 '15 at 08:00
  • 1
    The `selected` content attribute value is both readable and writable as the `defaultSelected` IDL attribute/property of the ` – brianary Apr 01 '20 at 17:45
  • And what about non-standard, custom attributes. For example `
    ` and in javascript `myDiv.roka` different values. Why? What is the standard in this case?
    – sarkiroka Jun 08 '20 at 13:25