conditional loop in jquery selector

How can I select the first 3 div elements in the following example using jquery?

I want to select the div elements with status = 0 until I encounter any other value.

<div status='0'></div>
<div status='0'></div>
<div status='0'></div>
<div status='1'></div>
<div status='0'></div>

The following example I would only need the first 2 elements

<div status='0'></div>
<div status='0'></div>
<div status='1'></div>
<div status='1'></div>
<div status='0'></div>

Answers


var divs = [];
$('div[status]').each(function() {
    if ($(this).attr('status') === '0') {
        divs.push(this);
    } else {
        return false;
    }
});

Need Your Help

Can not import pygst under windows 7 (32bit)

python windows-7 gstreamer

I am using windows 7 (32bit) and python 2.7.3.

Java Tapestry: Clearing a count value after a t:if test

java html tapestry

I am printing the first 12 elements of a Comments array. After 12 have been printed, a "More" link is printed. I am doing this using a COMMENT_COUNT int, and iterating it on each comment printed. I...