0

Hi I am using jQuery load to grab a ahref from a link and then I want to load a div from the page im getting into a div so have tried this:

// lets load the contents
$('#navigationLinks a:not(:first-child)').click(function(event){

    $('#wrapper').animate({
        'left':'0px'
    });

    var href = $('#navigationLinks a').attr('href');
    $('#content').load(href + ' #resultDiv');

    event.preventDefault();

});

This is the HTML:

<div id="navigationLinks">
    <a href="index.html" id="dashboardHome">Dashboard Home</a>
    <a href="industry-overview.html" title="Industry Overview" class="first currentLink">Industry Overview</a>
    <a href="regions.html" title="Regions">Regions</a>
    <a href="industries.html" title="Industries">Industries</a>
    <a href="security-pipeline.html" title="Security Pipeline">Security Pipeline</a>
    <a href="audit-events-issues.html" title="Audit Events &amp; Issues">Audit Events &amp; Issues</a>
    <a href="account-filter.html" title="Account Filter">Account Filter</a>
    <a href="contractual-delivered-services.html" title="Contractual vs. Delivered Services" class="last">Contractual vs. Delivered Services</a>
</div>

I tried removing the space in ' #resultDiv' before the # but that didn't help, any help would be greatly appreciated.

1
  • Sorry I don't know the answer, but can you console.log() and confirm all the pieces are working: 1. event is firing 2. href is valid 3. that query for #content is returning something? Note you can use var href = jQuery(this).attr('href');. More efficient. Commented Feb 15, 2013 at 10:57

1 Answer 1

1

You should try this

$(document).ready(function(){

$('#navigationLinks a:not(:first-child)').click(function(e){
   var href = e.target;
   $('#content').load(href + ' #resultDiv');
   e.preventDefault();

});
});

The problem was that var href = $('#navigationLinks a').attr('href'); will always get the first link in the block and not the actually link that was clicked.

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

1 Comment

var href = e.target; - this didn't work by loading the url in the div with id of resultDiv

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.