mardi 25 février 2020

How to add Class on behalf after last dash (-) of URL in jquery?

I want to add the active class in the anchor tag on behalf after the last dash (-) of URL. because I have two URL

  1. http://www.example.com/information-pages
  2. http://www.example.com/information-blog

I'm using this script. It's is working well, but I want to add the active class after the last -

var path = window.location.pathname.split("/").pop();
var target = $('a[href*="' + path + '"]');
target.addClass('active');



Aucun commentaire:

Enregistrer un commentaire