D
D
dnv7772011-05-17 10:45:00
JavaScript
dnv777, 2011-05-17 10:45:00

jQuery: analogue of $('p').all() from prototype?

let's say there is a function
function valid(o){ ... ? true : false;}

and you need to check each element for validity
in prototype, this can be done like this
if( $('p').all(valid) ) alert('OK');<br/>

in jQuery, there is only each, which, when return false, stops the further passage through the elements,
but at the exit there is no way to check if the call was interrupted in this way,
you have to do this:

var b=true;<br/>
$('p').each(function(){<br/>
 if(! ....) {b=false; return false;}<br/>
};<br/>
if(b) alert('OK');<br/>


is there a more concise way in jQuery?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mark_ablov, 2011-05-17
@mark_ablov

if ($('p').is(valid))
Just keep in mind that the function should return true on failure, and not vice versa.

A
Anton Pronin, 2011-05-17
@nightw0rk

And so you will not be satisfied
if($('p').each(valid($(this).something))) alert ('OK') ;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question