learningjavascriptks learningjavascriptks - 4 months ago 7
Javascript Question

I cannot get .length of my li?

so I am doing my slider and somehow I want to get the .length/.size() of my li elements which contains images.

this is my code:

window.onload = function slider() {
$('#img1').show('fade', 500);
$('#img1').delay(5000).hide("slide",{direction:'left'},500);
}

var length = $('li').length();
console.log(length);
var count = 2;
setInterval(function () {
$('#img' + count).show('slide', { direction: 'right' }, 500);
$('#img' + count).delay(5500).hide('slide', { direction: 'left' }, 500);

if (count === sc) {
count = 1;
} else {
count += 1;
}
}, 6500);


I am getting this error

error

Answer

Length comes as a jQuery object's property so call it without ().

$('li).length

Or

$('li').size()

I see you mentioned it correctly in the first line of your question

" I want to get the .length/.size()".