DOM Controls that do things
When the user clicks the button the DOM gets changed.
Input
xxxxxxxxxx
let b = document.createElement('button');
b.innerText = 'click me';
b.onclick = ()=>{
document.body.append('Hello world');
}
document.body.append(b);
Output
let b = document.createElement('button'); b.innerText = 'click me'; b.onclick = ()=>{ document.body.append('Hello world'); } document.body.append(b);
let b = document.createElement('button'); b.innerText = 'click me'; b.onclick = ()=>{ document.body.append('Hello World!'); } document.body.append(b);
The user can change the text that gets echoed.
Input
xxxxxxxxxx
let i = document.createElement('input');
i.value = 'Andrew was here';
let b = document.createElement('button');
b.innerText = 'click me';
b.onclick = ()=>{
document.body.append(i.value);
}
document.body.append(i,b);
Output
let i = document.createElement('input'); i.value = 'Andrew was here'; let b = document.createElement('button'); b.innerText = 'click me'; b.onclick = ()=>{ document.body.append(i.value); } document.body.append(i,b);
let i = document.createElement('input'); i.value = 'Andrew was here'; let b = document.createElement('button'); b.innerText = 'click me'; b.onclick = ()=>{ document.body.append(i.value); } document.body.append(i,b);