If a ul has more than one li-element inside of it, something should happen, otherwise not!
What am I doing wrong?
if ( $(\'
If you have a dom object of the ul, use the following.
$('#my_ul').children().length;
A simple example
window.setInterval(function() {
let ul = $('#ul'); // Get the ul
let length = ul.children().length; // Count of the child nodes.
// The show!
ul.append('- Item ' + (length + 1) + '
');
if (5 <= length) {
ul.empty();
length = -1;
}
$('#ul_length').text(length + 1);
}, 1000);
Count of the child nodes: 0