I've got a small problem with the navigation framework I'm trying to implement on my site. Coded as follows:
HTML
<div class="panel1">
first navigation ul li set
</div>
<div class="panel2" id="subnav">
AJAX loaded navigation ul li set
</div>
<div class="panel3" id="content">
content loaded by AJAX
</div>
Javascript
$(document).ready(function () {
$('a.ajax-link-top').click( function( event ) {
set_ajax_link( $(this), event );
});
});
function set_ajax_link( el, event ){
event.preventDefault();
var url = el.attr("href");
load_menu_content( url );
}
function load_menu_content( url ){
$("#subnav").load( url, { 'ajax': 'true' }, function(){
$('#subnav a.ajax-link').click( function( event ) {
set_ajax_link_sub( $(this), event );
});
});
}
function set_ajax_link( el, event ){
event.preventDefault();
var url = el.attr("href");
load_page_content( url );
}
function load_page_content( url ){
$("#content").load( url, { 'ajax': 'true' }, function(){
$('#content a.ajax-link').click( function( event ) {
set_ajax_link_sub( $(this), event );
});
});
}
The fix is as follows:
HTML: same Javascript:
$(document).ready(function () {
var panel2 = $(".panel2");
var panel3 = $(".panel3");
$(".panel1").click(function (e) {
e.preventDefault();
var url = e.target.href;
$(".panel2").load(url);
});
$(".panel2").click(function (e) {
e.preventDefault();
var url_2 = e.target.href;
panel3.load(url_2);
});
});
The goal is to get links of the class ajax-link-top to load a subnav menu in the #subnav div, and to get links of the ajax-link class to load page content into the #content div, from either the top nav panel or the subnav panel.
The result I'm getting right now is that anytime any of the links are clicked, they load the content, menu or otherwise, into the #content div. I'm sure I just have something off in my JS code somewhere, but I can't see it.
Any and all help appreciated! M