Jack Pilowsky
Jack Pilowsky

Reputation: 2303

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,

Upvotes: 0

Views: 2735

Answers (2)

Ulises
Ulises

Reputation: 13419

  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.');
});

Upvotes: 1

Ricardo Lohmann
Ricardo Lohmann

Reputation: 26320

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.

Upvotes: 0

Related Questions