Reading Notes
Objects group a set of variables and functions of a model
var hotel = {
name: 'Quay', //property
rooms: 40, //property
booked: 25, //property
gym: true, //property
roomTypes: ['twin', 'double', 'suite'], //property
checkAvailability: function() { //Method, this is a function
return this.room - this.booked;
}
};
name: key property'Quay' value propertythis.room keyword “this” indicates that it is using the rooms property of this objectAccessing an object Dot Notation
var hotelName = hotel.name; //declares the variable hotelName and assigns the value 'Quay' dot notation
var roomsFree = hotel.checkAvailability(); //declares teh variable roomsFree an assigns the value of the function output dot notation
var hotelName = hotel['name']; //same as above using square bracket notation
var roomsFree = hotel['checkAvailability'](); //same as above using square bracket notation
DOM Document Object Model
API Application Programming Interface
DOM Tree Access and Update
getElementById(); uses the value of an element’s id to select an element’s nodequerySelector(); uses a CSS selector and returns the first matching elementgetElementsByClassName(); selects all elements that have a specific value ofr their classgetElementsByTagName(); selects all elements that have a specified tag namequerySelectorAll(); uses a css selector to select all matching elementsparentNode selects the parent of current element nodepreviousSibling / nextSibling selects previous or next sibling from DOM treefirstChild / lastChild selects the first or last child of current elementnodeValue property lets you access or update contents of a text nodeinnerHTML property allows access to child elements and text contenttextContent another just the text contentcreateElement() / createTextNode() / appendChild() / removeChild () let you create a new notes, add nodes to a tree and remove nodes from a tree, called DOM manipulationclassName / id lets you get or update value of the class or id attributeshasAttribute() / getAttribute() / setAttribute() / removeAttribute() first checks if attribute exists, second gets value, third updates value, fourth removes attributeCaching DOM Queries
getElementByID('one'); tells interpreter to find element whose id attribute is 'one', then can do work with it, its parent, or childvar itemOne = getElementByID('one'); variable stores a reference to the object in the DOM tree (storing the location of the node)Methods that select single elements
document.getElementById('one');
document refers to the document object. member operator, dot notation indicates that the method (on the right) is being applied to the nod on teh left of the periodgetElementById('one'); method, indicates that you want to find an element based upon the value of its id attribute'one' *parameter, value of the id attribute to find`