I have a site that is Ajaxed, content that is Ajax relates to other pages like about.html, contact.html. Ajax gets content from a div called # main-content. But after ajax call the rest of my scripts break. For example, the tinyscrollbar () plugin and some other custom functions.
I searched for about 4 days and found out that my problem was that the AJAX request changed the DOM, and since the scripts were loaded before that, it did not start after ajax call.
If I'm right, what do I need to fix? .Live () or the .livequery () plugin?
All used by me JS:
var $dd = $('.projects dl').find('dd'), $defBox = $('#def-box');
$defBox.hide();
$('.projects').hover(function(){
$defBox.stop(true, true)
.fadeToggle(1000)
.html('<p>Hover The links to see a description</p>');
});
$dd.hide();
$('.projects dl dt').hover(function(){
var $data = $(this).next('dd').html();
$defBox.html($data);
});
var hash = window.location.hash.substr(1);
if ($('a[href="' + hash + '"]').length) {
var toLoad = hash + '.php #main-content';
$('#main-content').load(toLoad);
}
$("nav ul li a").click(function(){
var goingTo = $(this).attr('href');
goingTo = goingTo.substring(goingTo.lastIndexOf('/') + 1);
if (window.location.hash.substring(1) === goingTo) return false;
var toLoad = $(this).attr('href')+' #main-content',
$content = $('#main-content'), $loadimg = $('#load');
$content.fadeOut('fast',loadContent);
$loadimg.remove();
$content.append('<span id="load"></span>');
$loadimg.fadeIn('slow');
window.location.hash = goingTo;
function loadContent() {
$content.load(toLoad,'',showNewContent)
}
function showNewContent() {
$content.fadeIn('fast',hideLoader);
}
function hideLoader() {
$loadimg.fadeOut('fast');
}
return false;
});
source
share