@smokey, thanks for the reply. perhaps an example would best illustrate if the problem is related to variable scopes or not.
well here is one of the scripts that wont work on its own (when isolated). It loops through all the elementss within an checking if the href attribute matches the url. If it does, it adds a class to the
parent of that element. The purpose is to highlight the appropriate menu item of the page being displayed.
[php]
$(document).ready(function() {
//Menu highlights.
var curURL = document.location.toString();
$('.topnav1 li.highlight').removeClass('highlight');
$('.topnav1 li a').each(
function(){
if (curURL.indexOf(this.href) != -1){
$(this).closest('li').addClass('highlight');
}
}
);
});
</script>[/php]
Well standing on its own, this script doesn’t work, but once I include it within the document ready method of another unrelated script, it works. Here’s what I mean.
[php] <script type = "text/javascript">
//To load ajax pages. And menu highlights.
$(document).ready(function() {
//Menu highlights.
var curURL = document.location.toString();
$('.topnav1 li.highlight').removeClass('highlight');
$('.topnav1 li a').each(
function(){
if (curURL.indexOf(this.href) != -1){
$(this).closest('li').addClass('highlight');
}
}
);
//Load pages via Ajax
// Check for hash value in URL
var hash = window.location.hash.substr(1);
var href = $('.topnav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html .wrapper_inner';
$('.wrapper_inner').load(toLoad)
}
});
$('.topnav li a').click(function(){
var toLoad = $(this).attr('href')+' .wrapper_inner';
$('.wrapper_inner').slideUp('fast',loadContent);
$('#load').remove();
$('#tier3').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('.wrapper_inner').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('.wrapper_inner').slideDown('slow',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});//End of ducument ready method
</script>[/php]
This I may add is just one example. I have two other scripts that didn’t work on their own but worked once I boxed them in with the above script.