Difference between revisions of "DOM content from lists"
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
<div class=qu> | <div class=qu> | ||
== Show a list of numbers == | == Show a list of numbers == | ||
*When you have data in a list you can use | *When you have data in a list you can use a for loop to generate content | ||
<pre class=usr> | <pre class=usr> | ||
for(let beatle of ['John", 'Paul', 'George', 'Ringo']){ | for(let beatle of ['John", 'Paul', 'George', 'Ringo']){ | ||
Line 11: | Line 11: | ||
</pre> | </pre> | ||
<pre class=ans> | <pre class=ans> | ||
for(let beatle of ['John | for(let beatle of ['John', 'Paul', 'George', 'Ringo']){ | ||
let div = document. | let div = document.createElement('div'); | ||
div.innerHTML = beatle; | div.innerHTML = beatle; | ||
document.body.append(div); | document.body.append(div); |
Revision as of 07:34, 26 August 2021
Show a list of numbers
- When you have data in a list you can use a for loop to generate content
for(let beatle of ['John", 'Paul', 'George', 'Ringo']){ let div = document.createElementById('div'); div.innerHTML = beatle; document.body.append(div); }
for(let beatle of ['John', 'Paul', 'George', 'Ringo']){ let div = document.createElement('div'); div.innerHTML = beatle; document.body.append(div); }