I'm going through a table with data, pressing search takes the value of the input and looks for it in the table, when it finds it I need to cut the execution of the function, which is what I can not do thanks.
function BuscarCodigo() {
$("#table tbody tr").each(function() {
if ($(this).find("td:eq(0)").text() == $('#codigo').val()) {
alert("codigo ya ingresado");
return false;//no funciona , no detiene la ejecucion de la funcion
}
});
//estos alerts no deberian mostrarse por que necesito detener la ejecucion en el "return false"
alert("llego");//aca no deberia llegar
alert("llego");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<input id="codigo" type="text">
<button type="button" onclick="BuscarCodigo()"> Buscar</button>
<table id="table">
<thead>
<tr>
<th>Codigo</th>
<th>Cantidad</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td>4859</td>
<td>2</td>
</tr>
<tr id="2">
<td>2568</td>
<td>2</td>
</tr>
</tbody>
</table>