Bits of code for manipulating the DOM
These are methods:document.getElementById()
document.querySelector()
document.getElementsByClassName()
document.getElementsByTagName()
document.querySelectorAll()
.innerHTML
The innerHTML property can be used to get or change any HTML element, including <html>
and <body>
.
adding and event listener.
Older things...
- First animal goes here.
- Second animal goes here.
- Third animal goes here.
- Fourth animal goes here.
- Fifth animal goes here.
Current list of fauna:
Using:function paragraphList() {
for (let i = 0; i < fauna.length; i++) { // let fauna=fauna[i].toUpperCase();
document.getElementById("plist").innerHTML=fauna.join(' and ');
}
}
quick test
Push to test external html.js file is working:
The idea
Is to get a list from an array into a paragraph with line breaks using <br>
.
The code:
function myList() {
let fauna = ["bear", "ox", "tiger", "gallimimus", "geoduck"];
for (let i = 0; i < fauna.length; i++) {
document.getElementById("animals" + i).innerHTML = fauna[i] + "<br>";
// boo = fauna;
}
alert("Each paragraph is given a different ID.");
}
Need some way to add to each time rather than replace.
Link
This is from W3 schools on output...