Currently, I am in the process of developing a basic contact list web application where the contacts are listed within li
elements. My aim is to adjust the visibility of the text in the p#no-contacts
element based on whether the containing ul
has any children or not. Ideally, when the ul
contains 0 children, the text should have a display: block
property, and if it contains one or more children, then the text should have a display: none
property. However, despite my efforts, this functionality doesn't seem to be working.
Please find the JSFiddle for reference - https://jsfiddle.net/stqyujhw/
The issue seems to lie around Line 94 in the JavaScript section:
if (contactList.children.length < 1) {
noContactsMessage.style.display = "block";
} else if (contactList.children.length >= 1) {
noContactsMessage.style.display = "none";
}
I am quite perplexed by what could be causing the problem. As I am still relatively new to JavaScript, any advice or guidance on troubleshooting this would be greatly appreciated. Thank you in advance.