To append new content at the end of an HTML file, you use
Usually, however, you want to update the content of some existing element in the document. To do that, you give the element an
id and then ask the document for a reference to that element's entry in the document object model (DOM) using
getElementById. To update the element's plain text content, you assign to its
getElementById finds the single element in your document that has the given ID. If you wish to grab references to several elements, you may use
getElementsByClassName. Both of these expect you to pass the tag name or class name as a parameter. If your search criteria is more complex, you may use
querySelectorAll, which expects an arbitrary selector just like you would use in CSS. For example, to select just the list items in the vowels
list, you write this query:
If the generated content contains HTML that you want the browser to interpret, you assign to its
createElement and a new text node with
createTextNode. You attach a child to its parent with
appendChild. For example, this code appends an anchor to the body element:
An element's individual attributes are set using
setAttribute. Try adding a text input after the anchor.
There is no guarantee that those links are valid or safe to browse.