How to escape from ... for each cycle and method at the same time?

I use the code below, repeating the selections. I checked if the parameter value has already been entered. It eludes everyone, but does not exit the method.

yeniIlacBagla_ilacBagla: function(){ $("#bagliIlaclar > option").each(function(){ if(this.value===$("#baglanacakIlacID").val()){ alert($("#baglanacakIlacAdi").val()+'\n adlı ilaç zaten bağlıdır!'); return; }else{ $("#bagliIlaclar").append($('<option></option>').val($("#baglanacakIlacID").val()).html($("#baglanacakIlacAdi").val())); } }); } 
0
source share
2 answers

According to jquery documentation I found the following

We can break the $ .each () loop at a specific iteration, making the callback function return false . Returning non-false is the same as continuing in a for loop; he will immediately proceed to the next iteration.

+5
source

From the documentation at http://api.jquery.com/each/ :

You can stop the loop from the callback function by returning false.

+1
source

All Articles