Loading meta data from another page using jQuery

707 Views Asked by At

I'm trying to use the jQuery load method to grab some meta data from another page and insert it in a <div>, but I'm a little stuck.

I'm using something similar on the other page in which I grab the location meta data and put it in a <p>. To do this I use the following:

<script>
  var locationMeta = $('meta[property="og:locality"]').attr('content');
  $( 'p.locationMeta' ).text( locationMeta );
</script>

For this new task, I need to use something like:

$( "#mydiv" ).load( "href #target" );

The #target in this case needs to be meta[property="og:locality"].

n.b. I've tried to load the p.locationMeta as the target. It loads but it's empty.

1

There are 1 best solutions below

2
Aschab On

I think you're getting load wrong. if you do load(url), url have to be a valid url, a path to the page you're trying to load. you can do load(url selector) like this:

$( "#mydiv" ).load( "test.html meta[property='og:locality']" );