1

Trying to bring in a specific DIV from a page called by the jQuery .load function.

This is the code i have:

<script type="text/javascript">
    $('ul.navigation li a').click(function() {
        $('#content-wrap').fadeOut(500);

            var targetPage = $(this).attr('href')

        setTimeout(function() {
            $('#content-wrap').load(targetPage, function() {
                $('#content-wrap').fadeIn(500);
            });
        });     
    return false;
    });

</script>

...and it works - but it calls the whole page, rather than a specific area...

Cheers!

1
  • 1
    Since this is a jQuery question rather than a WordPress question, I think it is better suited for StackOverflow and should be migrated. Agree/disagree? Commented Mar 28, 2011 at 15:26

1 Answer 1

4

You're trying to load a page fragment rather than the whole page. If you dig deeper into the documentation, you'll see you need to change your targetPage variable just slightly.

var targetPage = $(this).attr('href');
targetPage += " #content-wrap";

This will change the targetPage variable to something along the lines of http://site.url #content-wrap and will fetch the contents of the #content-wrap element rather than the whole page.

Sign up to request clarification or add additional context in comments.

1 Comment

I see! I am just starting to get my head around jQuery - it seems i was looking at the wrong part to fix! Thank you : )

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.