JQuery: adding a selector to an already selected object

Hi,

Using a regular selector, I can select the grand parent of the input text box (which is actually an element) and through .next () I selected the following line.

var nextOne = $(this).parent().parent().next();

From this next ro, I want to select an input text box that is ".foo", which is the grandson of this line.

How can this be achieved?

Edit: Each line is in the following html format:

<tr>
    <td  ><input alt="time" type="text" class="timefield start_time"/></td>
    <td  ><input alt="time" type="text" class="timefield end_time"/></td>
    <td  ><input type="text" class="programnamefield"/></td>                
</tr>

And the method that chekcs, if the end_time field is filled in, if so, change the start_time of the next line to the end_time of the previous one. And vice versa.

function autoCompleteTimes(){
    $('.end_time').change(function(){
        var nextOne = $(this).parent().parent().next();
// TODO
        });  
}
+3
source share
3 answers

find ( input.foo dom) ( )

nextOne.find('.foo');

nextOne.children('.foo');

nex

var end_time = nextOne.find('.end_time').val()
if (end_time != '') {
   // end_time is filled
   nextOne.next().find('.start_time').val(end_time);
}
+1

grandparent/next row,

var nextOne = $(this).parent(). parent(). next();

var nextFoo = $('. foo', nextOne);

+1

you can use the following code:

nextOne.find('.foo');

Hope this helps you :)

+1
source

Source: https://habr.com/ru/post/1768066/


All Articles