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

How does Binary Lambda Calculus encode parenthesis?

encoding lambda functional-programming lambda-calculus

How does the BLC encode parenthesis? For example, how would this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.