1.3.5 - Getting and Settings DOM Node Values Flashcards

1
Q

Which properties do we have for getting and setting Elements Nodes

A

.innerHTML

.innerText

.textContent

.outerHTML

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

Which properties do we have for getting and setting Text Nodes

A

.data

.nodeValue

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

.innerHTML for what is used?

Element Nodes or Text Nodes

A

Element Nodes

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

.innerText for what is used?

Element Nodes or Text Nodes

A

Element Nodes

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

.textContent for what is used?

Element Nodes or Text Nodes

A

Element Nodes

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

.outerHTML for what is used?

Element Nodes or Text Nodes

A

Element Nodes

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

.data for what is used?

Element Nodes or Text Nodes

A

Text Nodes

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

.nodeValue for what is used?

Element Nodes or Text Nodes

A

Text Nodes

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

.innerHTML What returns?

returns all markup inside the …, without the … (it gets the descendant)

A

returns all markup inside the selected area, without the wrapper that we selected (it gets the descendant)

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

.innerHTML what returns?

all the markup inside the selected area, without the wrapper, and with their descendants?

A

YES

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

.innerHTML what returns?

It´s true to say that it will return the HTML markup with the wrapper that we select?

A

NO

returns all markup inside the selected area, WITHOUT the wrapper that we selected (it gets the descendant)

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

.innerHTML what return?

A

returns all markup inside the selected area, without the wrapper that we selected (it gets the descendant)

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

.innerHTML

When setting content, it change the DOM and the source code?

A

YES, it changes the DOM

NO, it not change the source code

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

.innerHTML

What is a good practice, when we are using .innerHTML for setting content, if we are appending a lot of content to it?

A

To append the content, into a new variable like:

var newVar = ‘title’;

newVar += ‘More content’;

contenido.innerHTML = newVar;

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

.innerHTML

It’s possible to append content directly on the property?

A

YES

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

.innerHTML

If we had which nodes … that has a child text node, that includes the characters &, <, >, will returns what characters?

A

the nodes that need to have a child text node are:

div, span, noembed

returned characters:

&amp, &lt, &gt

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

.innerHTML

What can we use to get a correct copy of the text nodes that are child of elements: div, span, noembed , that has the characters:

&, <, >

A

We can use .textContent

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

Why we need to use .textContent with nodes elements like:

div, span, noembed

that has child text node, that includes the characters:

&, <, >

A

Because if we use .innerHTML will return the characters &amp, &lt, &gt

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

.innerText is it true that will return the following?

Returns all the text, without formatting and markups. It’s like if the user would highlighted the contents of the element with the cursor and then copied to the clipboard

A

YES

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

.innerText?

Returns …, without formatting and markups.

A

Returns all the text, without formatting and markups

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

.innerText?

It is true that will return all the text with the proper formatting and markups?

A

NO

It will return all the text, without formatting and markups

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

.innerText

We can say that it’s like if the user do what?

A

Would highlight the content of the element with the cursor and then copied to the clipboard.

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

.innerText?

What happens when we have a css rule “display: none”

A

Using .innerText, that section will be ignored, not returned

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

.innerHTML parse content as HTML, and takes longer to run?

What will be the output?

A

YES

output: text/HTML

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
.innerText will take styles into consideration? what it means?
YES it takes styles into consideration It means that, it won´t get hidden text for instance.
26
.textContent Returns all the content without interfering with css rules?
YES
27
.textContent If the element is a document, a docType, what it returns?
returns null document.textContent // null
28
.textContent to grab all text for the whole document we can use what?
document.documentElement.textContent
29
.textContent if the data is CDATA section, comment, text node, what will return?
returns the text inside this node
30
.textContent what will return?
get the content of all elements, including **script** and **style** elements ## Footnote **and all its descendants**
31
.textContent set ? When setting, it´s true that it will remove all of its children and relaces them with a single text node with the given value?
YES
32
.textContent It removes all the children and do what?
Removes all of its children and replaces them with a single text node with the given value.
33
.textContent It places a single text node with the given value, and replaces all?
YES
34
.textContent, What it does when setting content?
When setting, it will remove all of its children and relaces them with a single text node with the given value?
35
.innerText is aware of CSS styling? What will do with hidden elements?
Yes it´s aware of css styling DON´T return the text of hidden elements.
36
Who will return a hidden element, that was hidden with css? innerText or textContent
textContent
37
It´s true to say that Reflow is: computes the layout of the page, on an element recomputes the dimensiones and positions of the element, and all the children elements?
YES
38
Reflow in simple terms is: recom...
recomputes the dimensions and positions of elements and positions, also of their childrens, and finally calls for a final repaint.
39
Reflowing is very expensive, or not to performance?
YES IT is
40
Who will trigger REFLOW, innerText or textContent? and Why?
innerText will trigger reflow. Becase is aware of CSS styling.
41
To avoid reflow what we need to use if we want to add text to a node?
use textContent
42
Often in order to retrieve or write text within an element, people use innerHTML, however ...
.textContent often has better performance because the text is not parsed as HTML
43
when retrieving or writing text within an element, which one of these properties has better performance: .innerHTML or .textContent and why?
textContent Because the text is not parsed as HTML
44
which property will prevent a xss attack?
textContent, because it not parse HTML The most fundamental safe way to populate the DOM with **untrusted data** is to use the safe assignment property, textContent. element.textContent = "\<%=untrustedData%\>"; //does not executes code
45
.outerHTML return? Returns the markup and content, including the descendants... also, it includes the wrapper tag of the selection, or not?
Yes, it includes the wrapper tag of the selection
46
.outerHTML returns... HTML ...., including the ... and the ....
HTML markup and content, including the descendants and the wrapper tag of the selection
47
.outerHTML returns what?
HTML markup and content, including the descendants and the wrapper tag of the selection
48
.outerHTML setting can you append to the property itself?
NO
49
.outerHTML setting What is better to append to a new variable or directly in the property itself?
To a new variable, we can´t append to the property itself
50
when using .outerHTML to set a value, it´s going to grab the entirely element and re-writing it completely?
YES, the wrapper itself and its descendants
51
.outerHTML if the element is the root element of the document, what will happend?
will throw a DOMException with an error
52
.outerHTML setting What happens to the variable whose .outerHTML property was set?
While the element will be replaced, the variable whose .outerHTML property was set will still hold a reference to the original element
53
.outerHTML what will set?
The entirely element and completely re-write it, the wrapper element itself and his descendants
54
.data .nodeValue Will get / set almost the same result?
yes
55
When we can see a difference when getting value of text nodes with .data and .nodeValue?
when dealing with attributes values
56
When dealing with attributes what will return .data? It is consistent across text values and attribute values?
undefined NO, it´s not consistent
57
When dealing with attributes values, what will return .nodeValue? it is consistent?
returns the actual result of the attribute It is more consistent
58
Imagine an element-only navigation imagine: parent, siblings childrens (properties to access them)
59
When we are setting the value of a text node, it´s better to set a conditional check, why is that?
Because we need to prevent to change the nodeValue of an element, we need to check if it´s really a text node type
60
About "what", we need to be aware of, when we are setting the value of a node text type? Remember: element nodes VS text nodes
We need to check with a conditional if the node it´s really a text node type, and not an element node
61
What will happend if we use .data or .nodeValue when setting the value of an Element node type
It will give us an error, and nothing will change.
62
Which one is faster .nodeValue or .innerHTML? and why?
nodeValue .innerHTML parse HTML that´s why it takes longer
63
Which one parse text and which one uses straight text, .innerHTML or .textContent What are they outputs?
.innerHTML parse content as HTML and takes longer. Output text/HTML .textContent uses straight text, does not parse HTML, and is faster. Output: text/plain
64
.innerText, takes styles into consideration?
Yes, it won´t get hidden text for instance.
65
En el DOM, la palabra null significa, "que no existe"?
SI
66
En el DOM, que significa la palabra "null"
que no existe
67
In the code on the image, what are we going to return, and what it will happend to the ...more stuff... elements that we have?
Returned nodes: TEXT DIV TEXT UL ...... SCRIPT ...more stuff... will not be returned, at the moment of the script execution the browser did not read it yet, so the "more stuff" is not returned
68
.childNodes looks like an array, but is actually a ...
collection - a special array-like iterable object
69
.childNodes looks like an array or a collection (a special array-like iterable object) ?
Collection!
70
Why can´t you replace a child by something else assigning childNodes[i] = ...
Becase collections are read-only Changing the DOM needs other methods
71
If we keep a reference to elem.childNodes, and add/remove nodes into the DOM, they appear in the collection automatically? Why?
YES, they appear automatically Because almost all DOM collections with minor exceptions are live. They reflect the current state of DOM