Reputation: 145
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.
Upvotes: 3
Views: 10323
Reputation: 183
Works, Ive just tried it:
<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.
Upvotes: 2
Reputation: 4656
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');
Upvotes: 2