-1

My variable is defined as fallows:

$("figure.entry-featured-media-boxed").each(function () {
        var a_href = $(this).find('a').attr('href');

    });

And i want to populate the content from the meta with name : fbimg

<meta property="og:image" name="fbimg" content="" />

Can this be done ?

Thanks

em0tic0n
  • 292
  • 2
  • 16
  • Your question is a bit confusing. Do you want to add multiple `meta` tags to the DOM (as in one for each link in the matched set of elements)? – gfullam Aug 26 '15 at 14:19
  • no i just want to add the content that a_href contains ionto the content of the meta tag – em0tic0n Aug 26 '15 at 14:20
  • I asked because you are looping through what appears to be a set of elements. If you know you are only going to retrieve one element, you should skip the `each` loop and just reference the link's href directly. – gfullam Aug 26 '15 at 14:21

1 Answers1

0

This should do the trick:

$('meta[name=fbimg]').attr('content', a_href);

but in an each this would be pointless, since you will overwrite the value every time you're looping through the each...

Might be interesting for you to also check: Is it possible to use javascript to change the meta-tags of the page?

Community
  • 1
  • 1
Kristof Feys
  • 1,822
  • 1
  • 19
  • 36