Difference between revisions of "DOM div in div"

From ProgZoo
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 217: Line 217:


==Create a drop down list==
==Create a drop down list==
A dropdown list is a select element that contains option elements.
<select>
  <option>England</option>
  <option>Northern Ireland</option>
  <option>Scotland</option>
  <option>Wales</option>
</select>
<div class='qu'>
<div class='qu'>
<pre class='usr'>
<pre class='usr'>
Line 227: Line 235:
option2.innerHTML = 'B';
option2.innerHTML = 'B';
select.append(option2);
select.append(option2);
;</pre>
</pre>
<pre class='ans'>
<pre class='ans'>
let uk = document.createElement('div');
let select = document.createElement('select');
let en = document.createElement('div');
document.body.append(select);
let sc = document.createElement('div');
for (let c of ['England','Northern Ireland','Scotland','Wales']){
let ed = document.createElement('div');
  let option = document.createElement('option');
uk.innerHTML = 'UK';
  option.innerHTML = c;
en.innerHTML = 'England';
  select.append(option);
sc.innerHTML = 'Scotland';
}
ed.innerHTML = 'Edinburgh';
</pre>
document.body.append(uk);
</div>
uk.append(en);
uk.append(sc);
sc.append(ed);




let css = document.createElement('style');
==Create a drop down from a list==
document.head.append(css);
A dropdown list is a select element that contains option elements.
css.innerText = `
 
div{
<div class='qu'>
   border:solid;
<pre class='usr'>
   padding: 1ex;
const countries = ["France", "Germany", "Italy", "Spain"];
   margin: 1ex;
let select = document.createElement('select');
document.body.append(select);
for(let c of countries){
  let option = document.createElement("option");
  // Remember there are three steps to complete
}
</pre>
<pre class='ans'>
const countries = ["France", "Germany", "Italy", "Spain"];
let select = document.createElement('select');
document.body.append(select);
for (let c of countries){
   let option = document.createElement('option');
   option.innerHTML = c;
   select.append(option);
}
}
`;</pre>
</pre>
</div>
</div>

Latest revision as of 13:11, 7 June 2023


UK map

UK contains England

let a = document.createElement('div');
a.innerHTML = 'A';
let b = document.createElement('div');
b.innerHTML = 'B';
document.body.append(a);
a.append(b);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;
let a = document.createElement('div');
a.innerHTML = 'UK';
let b = document.createElement('div');
b.innerHTML = 'England';
document.body.append(a);
a.append(b);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;

UK contains England, England contains London

let a = document.createElement('div');
a.innerHTML = 'A';
let b = document.createElement('div');
b.innerHTML = 'B';
document.body.append(a);
a.append(b);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;
let a = document.createElement('div');
a.innerHTML = 'UK';
let b = document.createElement('div');
b.innerHTML = 'England';
let c = document.createElement('div');
c.innerHTML = 'London';
document.body.append(a);
a.append(b);
b.append(c);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;

UK contains England and Scotland

let a = document.createElement('div');
a.innerHTML = 'A';
let b = document.createElement('div');
b.innerHTML = 'B';
document.body.append(a);
a.append(b);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;
let a = document.createElement('div');
a.innerHTML = 'UK';
let b = document.createElement('div');
b.innerHTML = 'England';
let c = document.createElement('div');
c.innerHTML = 'Scotland';
document.body.append(a);
a.append(b);
a.append(c);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;

England and Scotland, England contains London

let a = document.createElement('div');
a.innerHTML = 'A';
let b = document.createElement('div');
b.innerHTML = 'B';
document.body.append(a);
a.append(b);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;
let a = document.createElement('div');
a.innerHTML = 'England';
let b = document.createElement('div');
b.innerHTML = 'Scotland';
let c = document.createElement('div');
c.innerHTML = 'London';
document.body.append(a);
document.body.append(b);
a.append(c);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;

UK contains England and Scotland, Scotland contains Edinburgh

let a = document.createElement('div');
a.innerHTML = 'A';
let b = document.createElement('div');
b.innerHTML = 'B';
document.body.append(a);
a.append(b);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;
let uk = document.createElement('div');
let en = document.createElement('div');
let sc = document.createElement('div');
let ed = document.createElement('div');
uk.innerHTML = 'UK';
en.innerHTML = 'England';
sc.innerHTML = 'Scotland';
ed.innerHTML = 'Edinburgh';
document.body.append(uk);
uk.append(en);
uk.append(sc);
sc.append(ed);


let css = document.createElement('style');
document.head.append(css);
css.innerText = `
div{
  border:solid;
  padding: 1ex;
  margin: 1ex;
}
`;

Create a drop down list

A dropdown list is a select element that contains option elements.

<select>
  <option>England</option>
  <option>Northern Ireland</option>
  <option>Scotland</option>
  <option>Wales</option>
</select>
let select = document.createElement('select');
document.body.append(select);
let option = document.createElement('option');
option.innerHTML = 'A';
select.append(option);
let option2 = document.createElement('option');
option2.innerHTML = 'B';
select.append(option2);
let select = document.createElement('select');
document.body.append(select);
for (let c of ['England','Northern Ireland','Scotland','Wales']){
  let option = document.createElement('option');
  option.innerHTML = c;
  select.append(option);
}


Create a drop down from a list

A dropdown list is a select element that contains option elements.

const countries = ["France", "Germany", "Italy", "Spain"];
let select = document.createElement('select');
document.body.append(select);
for(let c of countries){
  let option = document.createElement("option");
  // Remember there are three steps to complete
}
const countries = ["France", "Germany", "Italy", "Spain"];
let select = document.createElement('select');
document.body.append(select);
for (let c of countries){
  let option = document.createElement('option');
  option.innerHTML = c;
  select.append(option);
}