McDuck4 McDuck4 - 11 months ago 43
HTML Question

menu button active when clicked

I want to make my buttons in the menu bar active, when they are clicked. That also works fine on: portfolio, about, contact.

My Portfolio

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.


<?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>



<!-- 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>
<!-- begin logo in navigation -->
<a class="navbar-brand" href="index.php">
<img src="images/graphic/vouzalis-webdesign.png">
<!-- end logo in navigation -->

<div class="navbar-collapse collapse">
<ul class="nav nav-pills nav-main pull-right">

<!-- begin navigation items -->
<a href="index.php">Index</a>
<a href="services.php">Services</a>
<a href="portfolio.php">Portfolio</a>
<a href="aboutme.php">About Me</a>
<a href="contact.php">Contact</a>
<!-- end navigation items -->

<!-- end nav -->


$(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');

Answer Source

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