-3

I have a variable declared: var fburl = data.results[0].alias;

How can I pass the var value to the HTML data-type?

Example:

var myurl = data.results[0].alias;

<div class="myclass" data-url="value in myurl"></div>

===========

Apologize not able to explain clearly as I am no expert in js.

Get meta dynamically, and pass the values to addthis meta type. I used .attr and it works, but not for Twitter meta.

var mymeta = $('.addthis_inline_share_toolbox_4m3m');
        mymeta.attr('data-url', myurl);
        mymeta.attr('data-title', mytitle);
        mymeta.attr('data-description', mydesc);
        mymeta.attr('data-media', myimage);
  }
Mike Poole
  • 1,958
  • 5
  • 29
  • 41
emmm
  • 1
  • 4

1 Answers1

0

Get a reference to DOM element via using various methods and you can use Element.dataset property to get/set data-* custom attributes

document.querySelector('.myclass').dataset.url = data.results[0].alias;
Satpal
  • 132,252
  • 13
  • 159
  • 168