简体   繁体   中英

Jquery .html and .load

I'm trying to teach myself jQuery and I'm a little stomped with the load() method. I'm working on eBay listings. Yes, I know includes are not allowed on ebay. However, there is a workaround that has been around for a few years and ebay doesn't seem to be cracking down on it.

var ebayItemID='xxxxxxxxxxxxxx'; // This is eBay code. I cannot edit it. 

<h1 id="title"> TO BE REPLACED</h1>

$(document).ready(function(){
var link = "http://www.ebay.com/itm/" + ebayItemID + "?item=" + ebayItemID +   &viewitem=&vxp=mtr";
var newTitle = $('#title').load(link + "#itemTitle");
$('#title').html(newTitle);
});

What's the point of this. I want to show the item title on the description, but I want to do so dynamically,

  1. load will not work on different domains (ebay on your case)
  2. load will set the content directly to your element. You can't assign it to a var.
  3. If you would like to indicate you want to extract content from a specific element you need to add a space between your link and the element id:

You can find more info on the jQuery docs

$('#title').load(link  + ' #itemTitle', function() {
  alert('Load was performed.');
});

When you use load will place the returned html into the element(this case #title ).
So you don't need to call html after it.

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