JQuery issue when fetching data using .load ()

I have a table that, when a row is clicked, sends the first 6 characters of that row (ID) to a PHP page and loads the subsequent data into a div further down the page. The problem is that as soon as I click on the row to load the div, most jQuery events stop working (.hover, .sortElements), they are attached to the original table. Is there anyone out there who would know to "fix" or work around this issue, or is there something I just can't see.

<SCRIPT type='text/javascript'>
$(document).ready(function(){

$(".panel").hide();
$(".itemjobbutton").click(function(){
    $(".panel").slideToggle("200");
    return false;
});
var inverse = false;
$("#jobTable th").click(function(){
            var header = $(this),
                index = header.index();

            header
                .closest('table')
                .find('td')
                .filter(function(){
                    return $(this).index() === index;
                })
                .sortElements(function(a, b){

                    a = $(a).text();
                    b = $(b).text();

                    return (
                        isNaN(a) || isNaN(b) ?
                            a > b : +a > +b
                        ) ?
                            inverse ? -1 : 1 :
                            inverse ? 1 : -1;

                }, function(){
                    return this.parentNode;
                });

            inverse = !inverse;

        });

$('#jobTable tr').click(function(){
if($(this).index() != 0) {
    var thistext = $(this).text().substring(0,6);
    $("#joblistingDetail").load('jobview.php' , {jobID: thistext}).hide().slideDown('100');
    $("#jobTable tr").css("background", "#fff");
    $(this).closest('tr').css('background-color', '#C3D9FF');
}
});


});

$('#jobTable tr').hover(

function() {
    $(this).addClass('hover');
},
function() {
    $(this).removeClass('hover')
}
);

      

+3


source to share


1 answer


Yours is jobview.php

more than likely including its own version jquery.js

, which overrides the version on the parent page. Either remove it from jobview.php

or change yours .load

to only pull the html from the given selector, like

$("#joblistingDetail").load('jobview.php #target')

      



where #target

is a selector that selects a specific container to pull in.

+1


source







All Articles