Difference between revisions of "DOM Controls that do things"

From ProgZoo
Jump to navigation Jump to search
Line 1: Line 1:
<pre id='shellbody' data-qtp='clicky'></pre>
<pre id='shellbody' data-qtp='clicky'></pre>
<div class=qu>
<div class=qu>
When  the user clicks the button the DOM gets changed.
<pre class=usr>
<pre class=usr>
let b = document.createElement('button');
let b = document.createElement('button');
Line 13: Line 14:
b.innerText = 'click me';
b.innerText = 'click me';
b.onclick = ()=>{
b.onclick = ()=>{
   document.body.append('Hello world');
   document.body.append('Hello World!');
}
}
document.body.append(b);
document.body.append(b);
</pre>
</div>
<div class=qu>
The user can change the text that gets echoed.
<pre class=usr>
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);
</pre>
<pre class=ans>
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);
</pre>
</pre>
</div>
</div>

Revision as of 19:36, 4 September 2021


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);

The user can change the text that gets echoed.

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);