I can't seem to figure out why I keep encountering this error message. It keeps saying that my loadEventListeners
is not defined, but I'm unsure why this would be the case. Any advice or suggestions on this matter would be greatly appreciated.
//Setting up variables for UI elements
const form = document.querySelector('#post-form');
const postList = document.querySelector('.collection');
const clearBtn = document.querySelector('.clear-posts');
const filter = document.querySelector('#filter');
const postInput = document.querySelector('#post');
// Call function to load all event listeners
loadEventListeners();
//Function to load all event listeners
function loadEventListeners(){
//Add Event Listener for submitting a post
form.addEventListener('submit', addPost);
}
//Function to add a new post
function addPost(e){
if(postInput.value === ''){
alert('Please add a post before submitting');
}
//Creating li element
const li = document.createElement('li');
//Adding class
li.className = 'collection-item';
//Creating text node and appending it to li
li.appendChild(document.createTextNode(postInput.value));
//Creating a delete link element
const link = document.createElement('a');
//Adding class
link.className = 'delete-item secondary-content';
//Adding icon HTML
link.innerHTML= '<i class="fa fa-remove"></i>';
//Appending the link to li
li.appendChild(link);
//Appending li to ul
console.log(li);
e.preventDefault();
}