user1338176
user1338176

Reputation: 105

jquery load variable won't load contents

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.

Upvotes: 0

Views: 100

Answers (1)

psu
psu

Reputation: 379

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.

Upvotes: 1

Related Questions