简体   繁体   中英

Loading meta data from another page using jQuery

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"] .

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

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']" );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM