Reputation: 13
I am new to jQuery and JS and I encounter what I believe is a syntax problem, but I haven't been able to fix it on my own.
I am using the .load method to display content on a page, which works perfectly when I use the following bit of code :
$("#mydiv1 a")on('click', function ()
{
$("#mydiv2").load(this.href);
});
When calling this.href, however, the entire page is returned (as expected). I would like to be able to return only one element in this page: #myelement. This is where my problem occurs: the following code doesn't work.
$("#mydiv1 a")on('click', function ()
{
$("#mydiv2").load(this.href #myelement);
});
If my syntax is indeed incorrect, what would be the right way to put it?
Any help would be greatly appreciated.
Thanks.
Upvotes: 1
Views: 44
Reputation: 24638
Here is how to write it:
$("#mydiv2").load(this.href + ' #myelement');
Upvotes: 0
Reputation: 413826
You have to build a string:
$("#mydiv2").load(this.href + " #myelement");
Upvotes: 1