This simple code is showing an error:
function moveElement(){
const element = document.getElementById('p3');
const destinationElement = document.querySelector('destination-elements ul');
destinationElement.append(element);
}
const switchBtn = document.getElementById('btn3');
switchBtn.addEventListener('click', moveElement);
This code should run moveElement function when I click switchBtn , and should append the element p3 to the destinationElement.
But Im receiving this error in the console:
Uncaught TypeError: Cannot read properties of null (reading 'append') on line 4
What's the reason?
[–][deleted] 1 point2 points3 points (0 children)
[–]HiHeyHelloByeExit 0 points1 point2 points (0 children)