1

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.

1
  • Keep your browser developer console open so that you can see reported errors. Commented Sep 15, 2014 at 21:40

2 Answers 2

1

You have to build a string:

$("#mydiv2").load(this.href + " #myelement"); 
Sign up to request clarification or add additional context in comments.

Comments

0

Here is how to write it:

$("#mydiv2").load(this.href + ' #myelement'); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.