Gavin Reynoldson
Gavin Reynoldson

Reputation: 631

Add jQuery active class to menu on a specific url page load

I have a nav menu that opens (and closes) on-click.

I want the menu to be always open (without having to click) when a specific page loads.

It's currently set up as:

$('.menu').on('click', function() {
  $('.menu').toggleClass('active');
  $('nav').toggleClass('active');
});

I'm not sure how to get it to stay active on a specific page load.

I've tried this but can't get it to work.

if(window.location.href.indexOf("get-started")
$('.menu').toggleClass('active');
  $('nav').toggleClass('active');
});

Upvotes: 0

Views: 152

Answers (1)

wpgeek1311
wpgeek1311

Reputation: 91

Please try below code:

if(window.location.href.indexOf("get-started") {
  $('nav').addClass('active');
}

Add this code directly in document.ready.

Upvotes: 1

Related Questions