jQuery variable for URL

3

It's as follows, I have the following code:

$('body').on("click", ".delete", function() {
   $('#1').val($(this).parents('tr').find('td').eq(0).text());
});

That will fetch the id of a row from a corresponding table row clicked and I wanted to get that value and put it in the URL like this:

window.location('iframes/clientes_apagar.php?cliente_id="Aqui"')
    
asked by anonymous 17.12.2017 / 21:17

1 answer

1

You can do this as follows:

var id_ = $(this).closest('tr').find('td').first().text().trim();

Next, concatenate this value in window.location :

window.location('iframes/clientes_apagar.php?cliente_id="'+id_+'"');

Example:

$('body').on("click", ".delete", function() {
   var id_ = $(this).closest('tr').find('td').first().text().trim();
    $('#1').val(id_);
    // window.location('iframes/clientes_apagar.php?cliente_id="'+id_+'"');
    alert(id_); // apenas para visualização
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><table><tr><td>id1</td><td><aclass="delete" href="#">Exibir id da linha</a>
      </td>
   </tr>
   <tr>
      <td>
         id 2
      </td>
      <td>
         <a class="delete" href="#">Exibir id da linha</a>
      </td>
   </tr>
</table>
    
18.12.2017 / 00:27