I notice the syntax -
identifier.innerHTML = "text to display";
where the identifier is id="identifier"
works in Chrome 41.
Is this part of a proposed standard ?
Bill
I notice the syntax -
identifier.innerHTML = "text to display";
where the identifier is id="identifier"
works in Chrome 41.
Is this part of a proposed standard ?
Bill
This behavior--referring to an element by simply using its ID--has been there for years, but it's now deprecated and good to avoid. See Directly reference HTML elements or Why don't we just use element IDs as identifiers in JavaScript?. Spec is at http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object.
Yes,Each HTML element has an innerHTML property that defines both the HTML code and the text that occurs between that element's opening and closing tag. By changing an element's innerHTML after some user interaction, you can make much more interactive pages.
This property was initially implemented by web browsers, then specified by the WHATWG and W3C in HTML5. Old implementations may not all implement it exactly the same way. For example, when text is entered into a text input, Internet Explorer changes the value attribute of the input's innerHTML property but Gecko browsers do not.
<!DOCTYPE html>
<html>
<body>
<p id="demo" onclick="myFunction()">Click me to change my HTML content (innerHTML).</p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed!";
}
</script>
</body>
</html>