Check-Menus.com

highlight current page in menu with javascript

by Macy Krajcik Published 2 years ago Updated 2 years ago
image

How to Highlight Current Page Menu Item with vanilla JavaScript

  • Step 1: A simple menu <nav class="navbar"> <a href="/"> Home </a> <a href="/about"> About </a> <a href="/contact">...
  • Step 2: CSS styling Some minimal CSS styling. The important part here is the .current class, which is what we will add...
  • Step 3: JavaScript

Full Answer

Can you highlight the current page in PHP with JavaScript?

An example where javascript would come in handy to highlight the current page is... Suppose you where using JS to swap panels all on the same page. Well, in cases such as those, we'd have to use javascript to give us what we want. I should note though, that statement is not entirely true. You "can" use PHP to do it, but it's a little complicated.

How to create a highlighted menu with CSS?

In the CSS section, I put a line for a separate menu and pages. Between the menu and page section, I put the underline effect to create the highlight. I put a span with 3px height with a color, It’s width is decided according to the menu’s words length using JavaScript.

How to highlight the current page or section in a link?

Whenever one builds a website, one issue is always guaranteed time consuming: highlighting the current page or section in the website with a different style. In theory, this is relatively simple, just add a .current class to the link in question.

How do I highlight the current page or section in WordPress?

Whenever one builds a website, one issue is always guaranteed time consuming: highlighting the current page or section in the website with a different style. In theory, this is relatively simple, just add a .current class to the link in question. So, if you have a menu styled from a list, you’d have:

image

How do I highlight the current page in navigation bar?

0:102:44Navigation: highlighting the current page - YouTubeYouTubeStart of suggested clipEnd of suggested clipCurrent to denote that this is the navigation that I want to highlight. So let me open up my CSS.MoreCurrent to denote that this is the navigation that I want to highlight. So let me open up my CSS. And down here I'm going to target nav. Current and let's just give it a different background. Color.

How do you highlight the current page in HTML?

If you want to highlight the "current" menu entry, you have to make it discernible to CSS by making it special in the HTML code - for example by adding a class "active" or "current".

How do you highlight the current menu in CSS?

Below are the steps to add a CSS class to the menu and highlight it using a custom CSS. Step 1 – From the WordPress dashboard navigate to Appearance > Menus. Step 2 – Click on Screen Options and tick the CSS Classes checkbox. Step 3 – Click on the menu item that needs to be highlighted.

How do I highlight the selected menu item in jQuery?

Re: Highlight the Selected Menu Item with one href ="/"