Brooks Patton
I have been working in the IT field for most of my professional career, first as a Systems Administrator at NASA Ames Research Center, as a software developer, and now I am an instructor at Galvanize.
dom-dom-dommmm
Research what is the DOM using google
Turn and talk to discuss what you found
The browsers provide the document object for us
'use strict';
let title = document.getElementById('title');
let titleText = title.textContent;
console.log(titleText);
Check out the contents of the title object!
console.log('title');
console.dir('title');
We can use the object that we had previously retrieved
'use strict';
let title = document.getElementById('title');
title.textContent = 'Hello World!';
.textContent is not the only property that we can modify the title object
title.innerHTML = 'Hello World!';
Search for
"mdn dom element"
Those pesky users keep on expecting things to happen when they click on things
'use strict';
let title = document.getElementById('title');
title.addEventListener('click', () => {
console.log('I was clicked!');
});
There are many other events that can be fired! Look them up on mdn with the search terms
"mdn event list"
The real power is in creating our own elements in JavaScript.
'use strict';
let newItem = document.createElement('li');
newItem.textContent = 'I am a new item!';
Just creating the element is nice and all, but it would be nicer if it made its way onto the screen
'use strict';
let list = document.getElementById('list');
let newItem = document.createElement('li');
newItem.textContent = 'I am a new item!';
list.appendChild(newItem);
There are other methods to add an element to the screen. Look them up on MDN
By Brooks Patton
This slide deck is for introducing the student to the DOM.
I have been working in the IT field for most of my professional career, first as a Systems Administrator at NASA Ames Research Center, as a software developer, and now I am an instructor at Galvanize.