Selecting Elements and Adding Events Flashcards
1
Q
document.getElementById
A
- returns a reference to the element by its ID
- element is a reference to an Element object, or null if an element with the specified ID is not in the document
- id is a case-sensitive string representing the unique ID of the element being sought.
2
Q
document.getElementsByTagName
A
- returns an HTMLCollection of elements with the given tag name
- HTMLCollection is an interface representing a generic collection (array) of elements (in document order) and offers methods and properties for selecting from the list
- elements is a live HTMLCollection of found elements in the order they appear in the tree
- name is a string representing the name of the elements
- the special string “*” represents all elements
3
Q
Select the H1 tag with the id of full_name and assign it to the variable fullName
A
var fullName = document.getElementById(“full_name”);
5
Q
Select the second SPAN element on the page and assign it to the variable lastName
A
var lastName = document.getElementsByTagName(“span”)[1];
6
Q
GlobalEventHandlers.onclick
A
The onclick property returns the click event handler code on the current element
7
Q
Assign the greeting event handler to the click event on the sayButton
A
sayButton.onclick = greeting;