Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery getting data from data-href

I am trying to make a table row a link by using jQuery and this:

jQuery(document).ready(function() {
    $(".clickable-row").click(function() {
        window.location.href = $(this).data('href');
    });
});

In my html file i have this:

<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>

Nothing is happening. If i change to this: window.location.href = 'www.google.com'; it's working so I know WERE the problem is...

What am I missing?

Edit: Plunker: http://plnkr.co/edit/0MBucaxR1fDpYZjZRLHc?p=preview

For some reason above doesn't work for me. If I use this it works:

jQuery(document).ready(function() {
    $(".clickable-row").click(function() {
        window.location.href = '**any link at all**';
    });
});

But when i change to this my console log don't even recognize my click...??

jQuery(document).ready(function() {
    $(".clickable-row").click(function() {
        window.location.href = $(this).data('href');
    });
});
like image 426
Dunken Avatar asked Jul 27 '26 08:07

Dunken


1 Answers

I did this:

jQuery(document).ready(function() {
    $(".clickable-row").click(function() {

        thisdata = $(this).attr('data-href');
        console.log(thisdata);

        window.location.href = thisdata;
    });
});

And the console gave me the correct answer.

I noticed that my actual table looked like this:

<tr class='clickable-row' data-href='URL://my-page.com/user/123'>

So by removing the URL:// it works now.

Thand you for your help!

like image 69
Dunken Avatar answered Jul 28 '26 22:07

Dunken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!