DOM Controls that do things
Jump to navigation
Jump to search
A button
When the user clicks the button the DOM gets changed.
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);
An input box and a button
The user can change the text that gets echoed.
let i = document.createElement('input'); i.value = 'Say it twice'; 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 = 'Say it twice'; let b = document.createElement('button'); b.innerText = 'click me'; b.onclick = ()=>{ document.body.append(i.value); document.body.append(i.value); } document.body.append(i,b);