How to change the value of find in a table with a popup?

2

I have the following problem, I open a popup window. pressing the save button updates the current tr of the table. This does it very well with this:

parent = linkObj.closest("tr");
                             parent.find('td, th').css('background-color', '#58ACFA');

But inside this pop-up window I have a button that goes to the next record.

With this code obitne the following registry without problem:

parent = linkObj.closest("tr").next('tr');

But if I want to get to the third one, he will not let me.

Try doing a foreach to see if you were assigning the next parent to the object.

But the .next only gets the following from the orginal:

for (var i = 0; i <= contador; i++)
                          {
                              parent = linkObj.closest("tr").next('tr');

What would be the correct way to do this?

Thank you.

    
asked by LoganFenix 13.03.2018 в 01:37
source

2 answers

1

An alternative is to use a variable to detect the position of your row and from there increase its value +1 in case you press the button that goes to the next record.

then with that variable you can access the row, because that variable corresponds to the index of your row

see the following example to arm

var position = 0;

$('.link').click(function() {
  position = $('tbody tr').index($(this).closest('tr'));
  $('tbody').find('tr').eq(position).css('background-color','#58ACFA');  
});

$('.btn').click(function() {
  ++position;
  $('tbody').find('tr').eq(position).css('background-color','#58ACFA');  
});

the function eq returns the element that matches that index in the selector and there you apply the style

the next button that I put outside the table, is the button that goes to the next record

    
answered by 13.03.2018 / 02:40
source
0

Thank you very much Mauro.

I added the following to the code and it is perfect

if (recorremodal == 0)                  {        parent = linkObj.closest ("tr");        parent.find ('td, th'). css ('background-color', '# 58ACFA');                  }

             else
               {

                      $('tbody').find('tr').eq(recorremodal).css('background-color', '#58ACFA');

                     }
    
answered by 13.03.2018 в 16:21