conditional loop in jquery selector -
how can select first 3 div elements in following example using jquery?
i want select div elements status = 0 until encounter 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 need first 2 elements
<div status='0'></div> <div status='0'></div> <div status='1'></div> <div status='1'></div> <div status='0'></div>
var divs = []; $('div[status]').each(function() { if ($(this).attr('status') === '0') { divs.push(this); } else { return false; } });
Comments
Post a Comment