window and document.Math and Date.Math.round().document.title (the title of the current page).document.querySelector()<body>
<h1 class="intro">Hello world!</h1>
</body>const headingElement = document.querySelector('h1');document is the top-level DOM variable that represents the HTML element;.querySelector() finds the first HTML element that matches the provided CSS selector;<body>
<h1 class="intro">Hello world!</h1>
</body>All of these selectors will create the same DOM variable:
const headingElement = document.querySelector('h1');const headingElement = document.querySelector('.intro');const headingElement = document.querySelector('body > h1');Element.innerHTMLAccessing HTML Content
<body>
<h1 class="intro">Hello world!</h1>
</body>// Create DOM variable
const headingElement = document.querySelector('h1');
// Access element content with .innerHTML property
const h1Content = headingElement.innerHTML; // 'Hello world!'Element.innerHTMLEditing HTML Content
<body>
<h1 class="intro">Hello world!</h1>
</body>// Create DOM variable
const headingElement = document.querySelector('h1');
// Edit element content with .innerHTML property
headingElement.innerHTML = 'Hello Tony!';After:
<body>
<h1 class="intro">Hello Tony!</h1>
</body>Element.innerHTMLCreating new elements
// Edit element content with .innerHTML property
headingElement.innerHTML = 'Hello <em>Tony</em>!';<body>
<h1 class="intro">Hello <em>Tony</em>!</h1>
</body>prompt()const name = prompt("What's your name?");
const h1 = document.querySelector('h1');
const name = prompt("What's your name?");
h1.innerHTML = `Hello ${name}!`;
<body>
<h1 class="intro">Hello Tony!</h1>
</body>.querySelector() method;.innerHTML works both ways when reading and writing content to and from HTML elements;.innerText can be used if you don't want HTML tags included;prompt() is rarely used professionally; we're using it as a short cut for now;Math.round()Rounds numbers inside the parentheses
Math.round(55.5) // 56Rounds .5 up to the nearest whole number.
Math.floor()Math.floor(55.9) // 55Rounds all decimals down to the nearest whole number.
Math.ceil()Math.floor(55.1) // 56Rounds all decimals up to the nearest whole number.