Andy
Andy

Reputation: 19251

Count element with Style Val = 0?

I was wondering how to count a list of <li> with a style val = 0 ?

i.e. something like

jQuery('ol.myClass li').each(function () {
    if (jQuery(this).css('top') == '0px') {
        count = + 1;
    }
});

How would I do this so it finds all elements and gives me a figure for all those that have the val = 0 for css('top') ?

Upvotes: 1

Views: 163

Answers (3)

Burntime
Burntime

Reputation: 2344

I would say try this way.

var list = $("ol.myClass li").filter(function() { 
  return $(this).css("top") === "0px";
});

list.length

Upvotes: 1

Jules
Jules

Reputation: 7223

It looks good.

But your count should be:

$count += 1;

or

$count++;

Upvotes: 0

Ayman Safadi
Ayman Safadi

Reputation: 11552

Try something like:

var foo = $('ol.myClass li').filter(function() {
    return $(this).css('top') == '0px';
});

Upvotes: 1

Related Questions