A new line for li's causes a JavaScript error [duplicate]
A new line for li's causes a JavaScript error [duplicate] This question already has an answer here: What I meant by a new line I was referring to by forcing the text in the code editor to move down the next line for readability not to be confused by the n term. Any ways I have this script that removes the ul next sibling by pressing a button everything works perfectly but I did not like how in the code editor the two li's were next to each other so as soon as I put the second li on a new line my code generated an error on line 6 it said Uncaught TypeError: Cannot set property 'display' of undefined. This is what I mean in the code editor The non-working one document.addEventListener('DOMContentLoaded',function(){ document.querySelector('button').addEventListener('click',fx); function fx() { document.querySelector("#message li").nextSibling.style.display= 'none'; } }); <ul id='message'> <li>Coffee...