我已经收录了我的标题&使用jQuery中的.load()
在单独的html文件中页脚。我的jQuery代码如下:
$(function(){
$("#header").load("page-component/header.html");
$("#footer").load("page-component/footer.html");
});
现在,当我导航到另一个页面时,我想在我的页眉/页脚链接中添加一个active
类,但我似乎无法实现这一点。有人可以帮帮我吗?
我尝试过这样的事情,但它没有工作:
$(document).ready(function(){
jQuery('#menu-about').addClass('active');
});
答案 0 :(得分:3)
使用jQuery.load
方法的complete callback
。
.load( url [, data ] [, complete ] )
当您为元素调用addClass
方法时,element
中不存在DOM
,callback
文件{{1}时调用external
函数在指定的loaded
element