I have got html as below
<a href="" data-href="/somefile.php?id=10&refcode=/test.php">Hello</a>
and I need to replace href with the value in data-href so that the above becomes something like
<a href="/somefile.php?id=10&refcode=/test.php">Hello</a>
//the following doesnt work ..
$(function() {
$('a[data-href]').attr('href', $(this).attr('data-href'));
});
Any suggestions? Basically I want to hide some links for some reason from search engines/bots etc. so I am happy if I can get the above working or if you can suggest any better idea to achieve the same? Thanks.
$(this)does not refer to theaelement in this case.Try
using
each(function() {})will bind thethiskeyword to theaelement inside the function.