Element.textContent
Gets and sets text inside an element.
Get value
const myHeading = document.getElementsByTagName('h1');
myHeading.textContent
// Output: "Hello, world!"
Set value
myHeading.textContent = "This is a new heading";
Same as:
myHeading.innerHTML = "This is a new heading 2";
Element.innerHTML
Gets and sets HTML code inside an element.
Get value
let ul = document.querySelector('ul');
ul.innerHTML
/* Output:
<li>grapes</li>
<li>lavender</li>
<li>plums</li>
*/
Set value
ul.innerHTML = `<li>red cabbage</li>`;
// Output: <li>red cabbage</li>
Element.attribute
Get value
input.value; // "Hello"
input.type; // text
input.className; // description
Set value
input.type = 'checkbox'; // Input changed to checkbox
a.title = "Homepage"; // Sets content of title attribute