basic dom manipulation Flashcards

1
Q

creation

A

var div = document.createElement(‘div’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

addition

A

document.body.appendChild(div);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

style manipulation

A

div.style.left = “32px”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

change class

A

div.className = “xxx”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

change id

A

div.id = “test”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

change inner html

A

div.innerHTML = “xx”but using jquery would be xx.html(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

change inner text

A

div.textContent = “hello”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

removal

A

div.parentNode.removeChild(div);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

get by id

A

div = document.getElementById(“id”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

get by tags

A

array = document.getElementByTagName(‘div’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

get by class

A

array = document.getElementsByClassName(‘class’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

get by css selector (single)

A

div = document.querySelector(‘div #test’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

get by css selector (multi)

A

array = document.querySelectorAll(‘div’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what are text nodes?

A

hello”hello” is h1’s child textNode. strictly speaking, it’s a node too. :D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

sibling (text node indluded)

A

node = div.nextSibling;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

children (text node indluded)

A

node = div.childNodes[i];

17
Q

sibling html node:

A

element = div.nextElementSibling;

18
Q

children html node:

A

element = div.children[i];