Jpaji Rajnish Jpaji Rajnish - 7 months ago 11
Javascript Question

Can't set the data-href attribute of fb widget

I have a variable that changes depending on which host my webpage is running and I'm trying to dynamically set the

data-href
attribute of the fb share widget but I can't get it to be set to anything, it just remains unchanged. This is the last thing I tried:

$( ".fb_iframe_widget" ).data( "href", CONFIG['domain'] );

Answer

You have to use .attr() in order to set data-* value as shown :-

$( ".fb_iframe_widget" ).attr("data-href", CONFIG['domain']);
Comments