Do Now: Get into your teams!
Style elements with classes and ids
Learn DOM manipulation with Javascript
Our activity: Task Tracker
Where do I put script tag?
Read this!
const para = document.getElementById('stylish-paragraph');
para.innerHTML = 'I say something else';
para.textContent = "I am a paragraph!"
Examples:
Examples:
const btn = document.getElementById('btn');
const para = document.getElementById('p');
btn.addEventListener('click', () => {
para.classList.toggle('bold');
});
Example
function add(a, b) {
return a + b;
}
console.log(add(10, 5));
const subtract = (a, b) => {
return a - b;
};
console.log(subtract(9, 2));
Lets look!
Input elements let us create interactive UI components for the user and we can get and set the value with JavaScript
const btn = document.querySelector('button');
const inp = document.querySelector('#operand');
btn.addEventListener('click', () => {
const num = parseInt(inp.value, 10); // .value
inp.value = num + num; // and it can be written!
});
Example
Other resources: