Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exit mootools each()

How can I exit the each function when the conditions was true once?

This does not work:

  $$('.box div').each(function(e) {
 if(e.get('html') == '') {
    e.set('html', 'test');
    exit;
 }
  });
like image 329
Billy Avatar asked May 11 '10 11:05

Billy


1 Answers

Use .some?

  $$('.box div').some(function(e) {
     if(e.get('html') == '') {
        e.set('html', 'test');
        return true;
     } else
        return false;
  });

But probably you could just use

  arr = $$('.box div[html=""]');
  if (arr.length > 0)
     arr[0].set("html", "test");
like image 57
kennytm Avatar answered Oct 14 '22 13:10

kennytm