const ul = document.querySelector('.items');
ul.remove();
const ul = document.querySelector('.items');
ul.lastElementChild.remove();
const ul = document.querySelector('.items');
ul.firstElementChild.textContent = 'Hello';
const ul = document.querySelector('.items');
ul.children[1].innerText = 'Brad';
ul.lastElementChild.innerHTML = '<h4>Hello</h4>';
const btn = document.querySelector('.btn');
btn.style.background = 'red';
const btn = document.querySelector('.btn');
btn.addEventListener('click', (e) => {
e.preventDefault();
console.log('click');
});
const myForm = document.querySelector('#my-form');
const btn = document.querySelector('.btn');
const ul = document.querySelector('.items');
btn.addEventListener('click', (e) => {
e.preventDefault();
myForm.style.background = '#ccc';
document.querySelector('body').classList.add('bg-dark');
ul.lastElementChild.innerHTML = '<h1>Hello</h1>'
})
const myForm = document.querySelector('#my-form');
const nameInput = document.querySelector('#name');
const emailInput = document.querySelector('#email');
const msg = document.querySelector('.msg');
const userList = document.querySelector('#users');
myForm.addEventListener('submit', onSubmit);
function onSubmit(e) {
e.preventDefault();
if (nameInput.value === '' || emailInput.value === ''){
msg.classList.add('error');
msg.innerHTML = 'Please enter all fields!';
setTimeout(() => msg.remove(), 3000);
}else {
const li = document.createElement('li');
li.appendChild(document.createTextNode(`${nameInput.value}: ${emailInput.value}`));
userList.appendChild(li);
//clear fields
nameInput.value = '';
emailInput.value = '';
}
}