DOM Document Flashcards

1
Q

document.activeElement

A

Returns the currently focused element in the document

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

document. addEventListener(event, function, ?useCapture)
event: A String that specifies the name of the event. (Note: Do not use the “on” prefix. For example, use “click” instead of “onclick”.)

function: Specifies the function to run when the event occurs.
When the event occurs, an event object is passed to the function as the first parameter. The type of the event object depends on the specified event. For example, the “click” event belongs to the MouseEvent object.

useCapture: A Boolean value that specifies whether the event should be executed in the capturing or in the bubbling phase. true - The event handler is executed in the capturing phase. false- Default. The event handler is executed in the bubbling phase

Ex:
document.addEventListener(“click”, function(){
document.getElementById(“demo”).innerHTML = “Hello World”;
});

A

Attaches an event handler to the document

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

document.adoptNode(node)

A

Adopts a node from another document

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

node.baseURI

var x = document.baseURI;

A

Returns the absolute base URI of a document

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

document.body

A

Sets or returns the document’s body (the element)

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

document.close()

ex:

document. open();
document. write(“<h1>Hello World</h1>”);
document. close();

A

Closes the output stream previously opened with document.open()

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

document.cookie

ex:
document.cookie=”username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/”;

A

Sets or returns all name/value pairs of cookies in the current document

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

document.createAttribute(attributename)

ex:
var h1 = document.getElementsByTagName(“H1”)[0];
var att = document.createAttribute(“class”);
att.value = “democlass”;
h1.setAttributeNode(att);

Note: Often, you will want to use the element.setAttribute() method instead of the createAttribute() method.

A

Creates an attribute node

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

document.createComment(text)

ex:
var c = document.createComment("My personal comments");
document.body.appendChild(c);
A

Creates a Comment node with the specified text

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

document.createDocumentFragment()

var d = document.createDocumentFragment();

d. appendChild(document.getElementsByTagName(“LI”)[0]);
d. childNodes[0].childNodes[0].nodeValue = “Milk”;
document. getElementsByTagName(“UL”)[0].appendChild(d);

from -Coffee -Tea to -Tea -Milk

A

Creates an empty DocumentFragment node, useful when you want to extract parts of your document, change, add, or delete, some of the content, and insert it back to your document.

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

document.createElement(nodename)

ex:
var btn = document.createElement(“BUTTON”);
var t = document.createTextNode(“CLICK ME”);
btn.appendChild(t);
document.body.appendChild(btn);

A

Creates an Element node

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

document.createTextNode(text)

var h = document.createElement("H1")                // Create a <h1> element
var t = document.createTextNode("Hello World");     // Create a text node
h.appendChild(t);</h1>
A

Creates a Text node

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

document.documentMode

A

Returns the mode used by the browser to render the document in IE

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

document.documentURI

can be used on any document types, whereas URL can only be used on HTML documents.

A

Sets or returns the location of the document

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

document.domain

A

Returns the domain name of the server that loaded the document

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

document.embeds

.length
[index]
item(index)
namedItem(id)

A

Returns a collection of all elements the document

17
Q

document.forms

.length
[index]
item(index)
namedItem(id)

A

Returns a collection of all elements in the document

18
Q

document. getElementById(elementID)

document. getElementById(“demo”);

A

Returns the element that has the ID attribute with the specified value

19
Q

document. getElementsByClassName(classname)

ex: var x = document.getElementsByClassName(“example color”);

A

Returns a NodeList containing all elements with the specified class name

20
Q

document.getElementsByTagName(tagname)

var x = document.getElementsByTagName("LI");
"*" returns all elements in document
A

Returns a NodeList containing all elements with the specified tag name

21
Q

document.hasFocus()

A

Returns a Boolean value indicating whether the document has focus

22
Q

document.head

A

Returns the element of the document

23
Q

document.images

A

Returns a collection of all <img></img> elements in the document

24
Q

document. importNode(node, ?deep)
deep: If set to false, only the node itself is imported, if set to true, all child nodes (descendants) are also imported

Tip: Use the document.adoptNode() method to remove and import a node from another document.

Tip: Use the element.cloneNode() method to copy a node from the current document.

A

Imports a node from another document

Clones the node

25
Q

document.lastModified

A

Returns the date and time the document was last modified

26
Q

document.links

.length
[index]
item(index)
namedItem(id)

A

Returns a collection of all <a> and elements in the document that have a href attribute</a>

27
Q

document.normalize()

A

Removes empty Text nodes, and joins adjacent nodes

28
Q

document.open(?MIMEtype, ?replace)

MIMEtype: The type of document you are writing to. Default value is “text/html”

replace: If set, the history entry for the new document inherits the history entry from the document which opened this document

ex:

document. open();
document. write(“<h1>Hello World</h1>”);
document. close();

A

Opens an HTML output stream to collect output from document.write() or document.writeln() methods. Once all the writes are performed, the document.close() method causes any output written to the output stream to be displayed.

29
Q

document. querySelector(CSS selectors)
document. querySelector(“.example”);

For multiple selectors, separate each selector with a comma. The returned element depends on which element that is first found in the document (See “More Examples”).

A

Returns the first element that matches a specified CSS selector(s) in the document

30
Q

document.querySelectorAll(CSS selectors)

var x = document.querySelectorAll(“p.example”);

A

Returns a static NodeList containing all elements that matches a specified CSS selector(s) in the document

31
Q

document.readyState

One of five values:
uninitialized - Has not started loading yet
loading - Is loading
loaded - Has been loaded
interactive - Has loaded enough and the user can interact with it
complete - Fully loaded

A

Returns the (loading) status of the document

32
Q

document.referrer

A

Returns the URL of the document that loaded the current document

33
Q

document.removeEventListener(event, function, useCapture)

A

Removes an event handler from the document (that has been attached with the addEventListener() method)

34
Q

document.scripts

A

Returns a collection of elements in the document

35
Q

document.title

A

Sets or returns the title of the document

36
Q

document.URL

A

Returns the full URL of the HTML document

37
Q

document.write(exp1, exp2, exp3, …)

var myWindow = window.open("", "MsgWindow", "width=200, height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
A

Writes HTML expressions or JavaScript code to a document

The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML.

38
Q

document.writeln(exp1, exp2, exp3, …)

writeln() method is identical to the document.write() method, with the addition of writing a newline character after each statement.

A

Same as write(), but adds a newline character after each statement