Reputation: 662
I want to make my buttons in the menu bar active, when they are clicked. That also works fine on: portfolio, about, contact.
But the small script is not working on index and services. I have set a body tag on each site.
Does anybody have a clue what could be wrong here? It is the exact same code.
services.php
<?php include 'resources/includes/header.php' ?>
<body id="services">
<?php include 'resources/includes/navbar.php' ?>
<!-- start intro section -->
<section class="intro">
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<div class="intro-content">
<h1>My services are <strong>focused </strong>primarily </h1>
<h2>in design, coding and marketing automation </h2>
</div>
</div>
</div>
</div>
</section>
navbar.php:
<!-- begin header section -->
<header class="header">
<!-- begin nav -->
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span>Tap me!</span>
</button>
<!-- begin logo in navigation -->
<a class="navbar-brand" href="index.php">
<img src="images/graphic/webdesign.png">
</a>
<!-- end logo in navigation -->
</div>
<div class="navbar-collapse collapse">
<ul class="nav nav-pills nav-main pull-right">
<!-- begin navigation items -->
<li>
<a href="index.php">Index</a>
</li>
<li>
<a href="services.php">Services</a>
</li>
<li>
<a href="portfolio.php">Portfolio</a>
</li>
<li>
<a href="aboutme.php">About Me</a>
</li>
<li>
<a href="contact.php">Contact</a>
</li>
<!-- end navigation items -->
</ul>
</div>
</div>
</div>
</div>
</nav>
<!-- end nav -->
</header
Javascript $(function() {
//highlight the current nav
$("#index a:contains('Index')").parent().addClass('active');
$("#services a:contains('Services')").parent().addClass('active');
$("#portfolio a:contains('Portfolio')").parent().addClass('active');
$("#about a:contains('About Me')").parent().addClass('active');
$("#contact a:contains('Contact')").parent().addClass('active');
});
Upvotes: 1
Views: 370
Reputation: 5003
You are missing the navbar.js script on those two pages. It's included below main.js on the ones that are working.
<!-- Custom Javascript -->
<script src="js/main.js"></script>
<script src="js/navbar.js"></script> // <-- missing from index and services
Upvotes: 3