I'm using twitter bootstrap with a menu that I'm trying to set the active class when an item is clicked. I'm able to remove and set the active class with a click event but after the header.php file loads with every new page the active class is removed. Is there a way to maintain the active class after the header file loads?
header.php
<ul class="nav menu">
<li><a href="test-page1.php">Test Page 1</a></li>
<li><a href="test-page2.php">Test Page 2</a></li>
<li><a href="test-page3.php">Test Page 3</a></li>
</ul>
footer.php
<script type="text/javascript">
$(document).ready(function() {
$('.menu li').click(function(e) {
$('.menu li.active').removeClass('active');
var $this = $(this);
if (!$this.hasClass('active')) {
$this.addClass('active');
}
});
});
</script>
test-page1.php
<?php
include_once dirname(__FILE__) . '/header.php';
?>
Some sample test data
<?php
include_once dirname(__FILE__) . '/footer.php';
?>