I try this:
<script type="text/javascript">
$(document).ready(function() {
$(".fb-like").attr('data-href',encodeURIComponent(location.href));
});
</script>
<div class="fb-like" data-href="" data-send="false" data-width="450" data-show-faces="false" data-font="verdana"></div>
But data-href is empty.
Works, Ive just tried it:
http://jsfiddle.net/MeE7B/
<div class="fb-like" data-href="" data-send="false" data-width="450" data-show-faces="false" data-font="verdana">
pippo
</div>"
After running the example inspect "pippo" with firebug or similar and you will see the attribute with correct value.
I retrieved data-href through $('.fb-like').data('href') and it seems to work for me.
check this out :http://jsfiddle.net/TFF2Z/1/
Anyway is a good solution to set data attributes like this :
$('.some-class').data('some-attr','some-value');
and then retrieve through
$('.some-class').data('some-attr');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With