Difference between revisions of "DOM div in div"
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
<pre class='usr'> | <pre class='usr'> | ||
let a = document.createElement('div'); | let a = document.createElement('div'); | ||
a.innerHTML = ' | a.innerHTML = 'UK'; | ||
let b = document.createElement('div'); | let b = document.createElement('div'); | ||
b.innerHTML = ' | b.innerHTML = 'England'; | ||
document.body.append(a); | document.body.append(a); | ||
a.append(b); | a.append(b); | ||
Line 22: | Line 22: | ||
<pre class='ans'> | <pre class='ans'> | ||
let a = document.createElement('div'); | let a = document.createElement('div'); | ||
a.innerHTML = ' | a.innerHTML = 'UK'; | ||
let b = document.createElement('div'); | let b = document.createElement('div'); | ||
b.innerHTML = ' | b.innerHTML = 'England'; | ||
document.body.append(a); | document.body.append(a); | ||
a.append(b); | a.append(b); | ||
Line 39: | Line 39: | ||
`;</pre> | `;</pre> | ||
</div> | </div> | ||
==A contains B, B contains C== | ==A contains B, B contains C== |
Revision as of 06:18, 11 September 2021
A contains B
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; } `;
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; } `;
A contains B, B contains C
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 = 'A'; let b = document.createElement('div'); b.innerHTML = 'B'; let c = document.createElement('div'); c.innerHTML = 'C'; 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; } `;
A contains B and C
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 = 'A'; let b = document.createElement('div'); b.innerHTML = 'B'; let c = document.createElement('div'); c.innerHTML = 'C'; 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; } `;
A and B, A contains C
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 = 'A'; let b = document.createElement('div'); b.innerHTML = 'B'; let c = document.createElement('div'); c.innerHTML = 'C'; 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; } `;
A contains B
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 = '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; } `;
A contains B
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 = '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; } `;