JavaScript Highlight current page navigation item highlight current page in menu with javascript,highlight current page

I have a floating page navigation list on my site. It has all the headers of the page, and the user can comfortably click the page navigation items to go to the correct anchor of the page. It also helps greatly in letting the visitor understand page structure, and to know where on the page he/she is.

Now, to help the user understand where on the page he/she is, I'd like for the correct item in the page navigation list to get highlighted (adding/removing CSS classes) depending on where the user is.

I hope I have explained myself well. How is this done? Thanks!

- EDIT -

Thanks Talgat for your answer. I now have this code:

<body ng-app="myApp">

This is my controller:

<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller("validateCtrl", function($scope) {
    $scope.isActive = {};
    $scope.isActive = function (state) {
        return state === $state.current.name;
    };
});
</script>

This is a anchor link from the navigation list to one of the tours we offer called "Ancestral Adventure":

<a target='_blank' href="#ancestral-adventure" ng-class="{active: isActive('ancestral-adventure')}">Ancestral Adventure</a>

"ancestral-adventure" is the id of a header. Perhaps I should wrap the "Ancestral Adventure"-content in a div instead with this id, though? This is the header:

<h3 id="ancestral-adventure" name="ancestral-adventure">Ancestral Adventure</h3>

As your angular code mentioned name in $state.current.name, I added a name and ng-name with same value to the header as well, just to be safe.

With this code, the navigation list items are not updated - nothing happens. I have made sure the active class works for the list items, and that the AngularJS library is working. What might I be doing wrong? Thanks!

Answer:1

You can use $state service to check is current navigation item is active or not. Here some example to realize that. Add following code to your controller:

$scope.isActive = function (state) {
  return state === $state.current.name;
};

and add this in templete:

<ul class="nav">
  <li ng-class="{active: isActive('route-name')}">
  </li>
</ul>

The active: isActive('route-name') will assign active class to the li tag if current item is active, then you can highlight that item with css.

Answer:2

i want to create marker on google map through dragging marker image from outside the map canvas and drop it inside the canvas, i've registered dom event listener of google maps but inside the listener ...

i want to create marker on google map through dragging marker image from outside the map canvas and drop it inside the canvas, i've registered dom event listener of google maps but inside the listener ...

  1. drag drop marker google maps
  2. drag and drop marker google map android
  3. drag and drop marker google map api
  4. drag and drop marker leaflet
  5. openlayers drag drop marker
  6. drag and drop marker
  7. mapbox drag and drop marker
  8. moodle drag and drop marker
  9. question drag and drop marker

Is there any function of Javascript or Jquery to make a button clicked by code? I already search on the internet but didn't see the answer for this. Thanks so much!

Is there any function of Javascript or Jquery to make a button clicked by code? I already search on the internet but didn't see the answer for this. Thanks so much!

  1. button onclick code
  2. button onclick code behind c#
  3. button onclick code in android studio
  4. button onclick code in html
  5. button onclick code unity
  6. button onclick code behind
  7. button onclick code in c#
  8. button onclick code android

Using Google Chrome (v42) and the native webcomponents support, I am trying to use a custom element, where the custom element content sometimes contains inlined javascript tags. However, the parser ...

Using Google Chrome (v42) and the native webcomponents support, I am trying to use a custom element, where the custom element content sometimes contains inlined javascript tags. However, the parser ...

  1. web component custom element
  2. web component custom element example
  3. @webcomponents/custom-elements npm
  4. @webcomponents/custom-elements/src/native-shim
  5. web component vs custom element

This is probably a trivial question, but I'm trying to look for the most efficient way to do this. I am given a string in this format "20130914" from a servlet and I need to create a javascript date ...

This is probably a trivial question, but I'm trying to look for the most efficient way to do this. I am given a string in this format "20130914" from a servlet and I need to create a javascript date ...

  1. javascript convert yyyymmdd to date
  2. javascript convert yyyymmdd to yyyy-mm-dd
  3. javascript convert yyyymmdd string to date
  4. javascript convert yyyymmdd
  5. js convert yyyymmdd to date
  6. convert yyyymmdd to date in javascript
  7. convert yyyymmdd to date js
  8. convert yyyymmdd to date javascript