admin管理员组文章数量:1303668
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/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'; it's working so I know WERE the problem is...
What am I missing?
Edit: Plunker:
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');
});
});
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./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.'; 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');
});
});
Share
Improve this question
edited Mar 12, 2017 at 19:44
Dunken
asked Mar 12, 2017 at 19:20
DunkenDunken
1031 gold badge1 silver badge10 bronze badges
9
-
Does
data-href
attribute setted dynamically? – Mohammad Commented Mar 12, 2017 at 19:23 - try $(this).attr('data-href'); and $('body').on('click', '.clickable-row', function() { ..your code here.. }); – ibrahimyilmaz Commented Mar 12, 2017 at 19:23
-
2
Console log
$(this).data('href')
to ensure it is what you think it should be. Also maybe you needhttp://
at the start. – Alan P. Commented Mar 12, 2017 at 19:24 - @mohammad : Not now but it will be when it's working. – Dunken Commented Mar 12, 2017 at 19:27
- Cannot reproduce plnkr.co/edit/0MBucaxR1fDpYZjZRLHc?p=preview – guest271314 Commented Mar 12, 2017 at 19:27
1 Answer
Reset to default 6I 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./user/123
'>
So by removing the URL:// it works now.
Thand you for your help!
本文标签: javascriptjquery getting data from datahrefStack Overflow
版权声明:本文标题:javascript - jquery getting data from data-href - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741772709a2396849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论