Skip to content

Instantly share code, notes, and snippets.

@ManishPoduval
Last active January 19, 2021 14:41
Show Gist options
  • Save ManishPoduval/09653f96730cc55774b61f92c07eb112 to your computer and use it in GitHub Desktop.
Save ManishPoduval/09653f96730cc55774b61f92c07eb112 to your computer and use it in GitHub Desktop.
console.log('INDEX.JS connected');
// ****************************** part 1 *********************************
function mySubmitEventListener(){
let myForm = document.querySelector('#new-task-form')
myForm.addEventListener('submit', e => {
e.preventDefault();
const taskInput = document.querySelector('#task-input');
const taskContent = taskInput.value;
const ownerInput = document.querySelector('#owner-input');
const ownerContent = ownerInput.value;
const ulParent = document.querySelector('#tasks-list');
const newLi = document.createElement('li');
newLi.innerText = `${taskContent} by ${ownerContent}`;
ulParent.appendChild(newLi);
taskInput.value = '';
ownerInput.value = '';
});
}
// ****************************** part 2 *********************************
function updateGif(){
const updateGifBtn = document.getElementById('update-button');
updateGifBtn.addEventListener('click', () => {
const gifTag = document.querySelector('iframe');
const currentGif = gifTag.className;
if (currentGif === 'three-minions') {
gifTag.setAttribute('src', 'https://giphy.com/embed/1MTLxzwvOnvmE');
gifTag.className = 'two-minions';
} else {
gifTag.setAttribute('src', 'https://giphy.com/embed/MOWPkhRAUbR7i');
gifTag.className = 'three-minions';
}
});
}
window.addEventListener('load', () => {
mySubmitEventListener()
updateGif()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment