Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click on a table row data should redirect to a html page using jquery

Tags:

html

jquery

In my html page, i have a table with few rows.If i click on a row, i need to redirect the page to another html page.How to perform this by using jquery.

Note:I need to redirect each row of data to distinct html pages.For example first row data should redirect to user1 profile html page.second row of data should redirect to user2 profile html page.

<table class="table">

    <tbody>
            <tr>
            <td>user 1</td>
            <td>10/21/2013</td>
            <td class="text-primary">Open</td>
            <td>$79.99</td>
            <td>Amazing Widget (16 GB, White)</td>
            <td>Johnathan</td>
            <td class="text-right none"> <a href="#" class="tick_icon gridneed_icon"></a>
 <a class="col-md-offset-1 cross_icon gridneed_icon" data-toggle="modal" href="#deleteproduct"></a>

            </td>
        </tr>
        <tr>
            <td>user 2</td>
            <td>6/21/2013</td>
            <td class="text-primary">Open</td>
            <td>$79.99</td>
            <td>Amazing (16 GB, White)</td>
            <td>Doe</td>
            <td class="text-right none"> <a href="#" class="tick_icon gridneed_icon"></a>
 <a class="col-md-offset-1 cross_icon gridneed_icon" data-toggle="modal" href="#deleteproduct"></a>

            </td>
        </tr>
    </tbody>
</table>
like image 916
user2089987 Avatar asked Oct 29 '25 02:10

user2089987


2 Answers

try something like this, use data attribute like below one

HTML CODE

<table class="table">
    <tbody>
        <tr data-url="some_url1">
            <td>39401602</td>
            <td>6/21/2013</td>
            <td class="text-primary">Open</td>
            <td>$79.99</td>
            <td>Amazing Widget (16 GB, White)</td>
            <td>Johnathan Doe</td>
            <td class="text-right none"> <a href="#" class="tick_icon gridneed_icon"></a>
    <a class="col-md-offset-1 cross_icon gridneed_icon" data-toggle="modal" href="#deleteproduct"></a>

            </td>
        </tr>
        <tr data-url="some_url2">
            <td>39401602</td>
            <td>6/21/2013</td>
            <td class="text-primary">Open</td>
            <td>$79.99</td>
            <td>Amazing Widget (16 GB, White)</td>
            <td>Johnathan Doe</td>
            <td class="text-right none"> <a href="#" class="tick_icon gridneed_icon"></a>
    <a class="col-md-offset-1 cross_icon gridneed_icon" data-toggle="modal" href="#deleteproduct"></a>

            </td>
        </tr>
    </tbody>
</table>

JAVASCRIPT CODE

$(function () {
    $('table.table tr').click(function () {
        window.location.href = $(this).data('url');
    });
})

REFERENCE

Data Attribute - http://api.jquery.com/data/

like image 87
rajesh kakawat Avatar answered Oct 31 '25 21:10

rajesh kakawat


Try using window.location.href

$('table tr').on('click', 'td', function () {
   window.location.href = "redirect url";
})
like image 23
Praveen Avatar answered Oct 31 '25 21:10

Praveen