Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change div data-href value

Tags:

jquery

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.

like image 775
Вълко Калъчев Avatar asked Aug 13 '26 18:08

Вълко Калъчев


2 Answers

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.

like image 143
jsfviky Avatar answered Aug 15 '26 09:08

jsfviky


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');
like image 29
steo Avatar answered Aug 15 '26 10:08

steo