Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
JQuery: How to select a specific input wrapped in a TD inside a table

I have a table, whose rows and td's are created with a foreach. So there is no predicting how many rows there might be. Each row has two buttons accompanied by an two adjacent input fields. See image:Table Image When you click a button, I need to grab the value inside it's adjacent input which is wrapped in a td. I have tried everything: prev(), closest(), eg(). And I can not figure out how to isolate the specific input on click. The best I have achieved is applying some css to ALL the inputs, but not the specific partnered input.

HTML

<tbody>
                @foreach($registeredChildren as $child)
                <tr>
                    <td class="col-2"><a href="'/getchild/'+ {{$child->child_id}}">{{$child->childFirstName}}</a>&nbsp &nbsp {{$child->childLastName}}</td>

                    <!--========TIME IN===========-->
                    <td class="col-3 pb-2 timeIn">
                        <input id="{{$child->child_id}}" class=" form-control " value="{{$child->timeIn}}" style="text-align:center;"  type="text">
                    </td>

                    <td><button class="btn btn-outline-success timeInReset">Reset</button></td>

                    <!-- //========TIME Out ===========//-->
                    <td class="col-3 pb-2"><input style="text-align:center;" class="form-control " type="text" ></td>
                    <td><button id="timeOut/{{$child->child_id}}" class="btn btn-outline-success out">Reset</button></td>
                </tr>
                @endforeach
           </tbody>

Script - This Does Not Work!

$(document).ready(function(){

$("button.timeInReset").click( function () {

 $(this).closest("td.timeIn>input").css({"color": "red", "border": "2px solid red"});

});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

closest doesn't look up sibling elements, but from current level up the DOM tree for parents.

For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree

$("button.timeInReset").click( function () {
    $(this).closest("tr").find("td.timeIn>input").css({"color": "red", "border": "2px solid red"});
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda