You can access elements of the DOM using document.getElementById("element-id")
or document.querySelector("#element-id")
. The querySelector()
method is a bit more flexible (you can use CSS-style selectors here) and should probably be preferred.
To get/set the content of an element, use the innerHTML method (to insert HTML directly into the DOM), or alternately innerText or textContent to set element text only.
Note that <script/>
tags inserted by setting an element’s innerHTML are not executed, however!