Estoy tratando de hacer que una fila de la tabla sea un enlace usando jQuery y esto:
jQuery(document).ready(function() { $(".clickable-row").click(function() { window.location.href = $(this).data('href'); }); });En mi archivo html tengo esto:
<tr class='clickable-row' data-href='my-page.com/user/123'> <td><span class="glyphicon glyphicon-user"></span></td> <td>{{ member.getFornamn }} {{ member.getEfternamn }}</td> <td>{{ member.getEmail }}</td> <td>{{ member.getTel1 }}</td> <td>{{ member.getPostadress }}</td> <td>{{ member.getPostnr }}</td> </tr>Nada esta pasando. Si cambio a esto: window.location.href = 'www.google.com'; está funcionando, así que sé DÓNDE está el problema...
¿Qué me estoy perdiendo?
Editar: Plunker: http://plnkr.co/edit/0MBucaxR1fDpYZjZRLHc?p=preview
Por alguna razón, lo anterior no funciona para mí. Si uso esto funciona:
jQuery(document).ready(function() { $(".clickable-row").click(function() { window.location.href = '**any link at all**'; }); });¿Pero cuando cambio a esto, el registro de mi consola ni siquiera reconoce mi clic...?
jQuery(document).ready(function() { $(".clickable-row").click(function() { window.location.href = $(this).data('href'); }); });Hice esto:
jQuery(document).ready(function() { $(".clickable-row").click(function() { thisdata = $(this).attr('data-href'); console.log(thisdata); window.location.href = thisdata; }); });Y la consola me dio la respuesta correcta.
Noté que mi tabla real se veía así:
<tr class='clickable-row' data-href='URL://my-page.com/user/123 '>
Entonces, al eliminar la URL: // funciona ahora.
¡Gracias por tu ayuda!