Welcome Guest, Not a member yet? Register   Sign In
JQuery show/hide div in Codeigniter - help!
#1

[eluser]Unknown[/eluser]
I designed my site in HTML/CSS while trying to decide on a web framework/language to use for the application. I decided to go with Codeigniter/PHP, and now the Jquery script I was using to show/hide divs needs (I think) a slight modification. It worked great with the HTML pages, but within CodeIgniter, I haven't been able to get it to work.

I've already autoloaded the javascript library and am calling the script in the header. Here's the code (w/o the script tags since I think they get removed on this forum).

Here's what the function does:
-it adds a hash (#) to the end of the page name so that people can refer back to it
-on clicking the menu links in the #nav area, it hides what is in the #content area on the current page, and loads the #content area from the href link that was clicked on

Any thoughts on how the code below can be adapted to CodeIgniter? I've been trying to get it to work for awhile:

Code:
$(document).ready(function() {  
  
    var hash = [removed].hash.substr(1);  
    var href = $('#nav li a').each(function(){  
        var href = $(this).attr('href');  
        if(hash==href.substr(0,href.length-5)){  
            var toLoad = hash+'.html #content';  //I tried changing this to .php, or removing it, but it still didn't work
            $('#content').load(toLoad)  
        }  
    });  
  
    $('#nav li a').click(function(){  
  
    var toLoad = $(this).attr('href')+' #content';  
    $('#content').hide('fast',loadContent);  
    $('#load').remove();  
    $('#wrapper').append('<span id="load">LOADING...</span>');  
    $('#load').fadeIn('normal');  
    [removed].hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);  
    function loadContent() {  
        $('#content').load(toLoad,'',showNewContent())  
    }  
    function showNewContent() {  
        $('#content).show('normal',hideLoader());  
    }  
    function hideLoader() {  
        $('#load').fadeOut('normal');  
    }  
    return false;  
  
    });
});







Theme © iAndrew 2016 - Forum software by © MyBB