const btns = document.querySelectorAll('button'), /* METHOD 1 */
wrapper = document.querySelector('.wrapper')btns.forEach(item => {
item.addEventListener('click', () => { /* METHOD 2 */
console.log('CLICKED');
})
})wrapper.addEventListener('click', event => {
if(event.target && event.target.matches(('button.red'))) { /* METHOD 3 - DELEGATSIYA */
console.log('CLICK');
}
})const button = document.createElement('button')
button.classList.add('blue')
button.textContent = 6
wrapper.append(button)
coding with ☕️
window.addEventListener('DOMContentLoaded', () => { })
Katta loyhalar uchun
coding with ☕️
setTimeout(() => { console.log('Hello World'); }, 2000);
Set Timeout function
// SetTimeout bu bitta function necha dur sekunddan keyin bir marotaba ishga tushadi
// SetInterval bu bitta function har necha dur sekunda ishga tushadi
const moveCar = () => {
const car = document.querySelector(".car");
let postion = 0;
const animationId = setInterval(moving , 5)
function moving() {
if (postion === 1000) {
clearInterval();
} else {
postion++;
car.style.left = postion + "px";
}
}
};
btn.addEventListener('click', moveCar)// Loading animatsiyasini yo'q qilish
const loaderWrapper = document.querySelector('.loader-wrapper');
setTimeout(() => {
loaderWrapper.style.display = 'none';
}, 1500);
// Timer
const deadLine = '2025-02-21';
function getTimeRemaining(endtime) {
const time = Date.parse(endtime) - Date.parse(new Date()),
days = Math.floor(time / (1000 * 60 * 60 * 24)),
hours = Math.floor((time / (1000 * 60 * 60)) % 24),
minutes = Math.floor((time / (1000 * 60)) % 60),
seconds = Math.floor((time / 1000) % 60);
return { total: time, days, hours, minutes, seconds };
}
// Funksiyani chaqiramiz va natijani ko'ramiz
console.log(getTimeRemaining(deadLine));