Jul 22, 2024
website
index.html
, style.css
, index.js
<link>
with rel="stylesheet"
and href="style.css"
<script>
with src="index.js"
at the bottom of body
<h1>
for headingslorem
in VS Code, then hit TAB.style.css
: Example body { font-family: Verdana; }
body
, h1
, p
console.log('Hello');
window.alert('This is an alert');
// This is a comment
/* This is a comment */
document.getElementById('id')
document.getElementsByClassName('class')
document.getElementsByTagName('tag')
document.querySelector('selector')
document.querySelectorAll('selector')
document.getElementById('myID').textContent = 'New Text';
const element = document.querySelector('.myClass');
element.style.color = 'red';
mouseover
, mouseout
)keydown
, keyup
)document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
});
document.getElementById('myButton').removeEventListener('click', myFunction);
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
});
});
const name = document.querySelector('#nameInput').value;
if (name === '') {
alert('Name is required!');
}
event.preventDefault();
let age = 25; // number
eventlistenerconsole.log(typeof age); // number
function sum(a, b) {
return a + b;
}
const sum = function(a, b) {
return a + b;
};
const sum = (a, b) => a + b;
const person = {
firstName: 'John',
lastName: 'Doe',
age: 30
};
const fruits = ['apple', 'banana', 'cherry'];
for (let i = 0; i < 5; i++) {
console.log(i);
}
let i = 0;
while (i < 5) {
console.log(i);
i++;
}
fetch('url')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
const fetchData = async () => {
try {
const response = await fetch('url');
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}
};
fetchData();