Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery active menu

$(function(){

    var url = window.location.pathname, 
        urlRegExp = new RegExp(url.replace(//$/,'') + "$"); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there
        // now grab every link from the navigation
        $('.menu a').each(function(){
            // and test its normalized href against the url pathname regexp
            if(urlRegExp.test(this.href.replace(//$/,''))){
                $(this).addClass('active');
            }
        });

});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript find object in array 
Javascript :: javascript wait async 
Javascript :: check if input is valid js 
Javascript :: hex string to int javascript 
Javascript :: how to get attr in vuejs 
Javascript :: ERESOLVE unable to resolve dependency tree npm ERR npm ERR! Found: @angular/core@5.0.3 npm ERR! node_modules/@angular/core 
Javascript :: how to get single element from nested array mongoose 
Javascript :: jquery after 
Javascript :: javascript group by key 
Javascript :: set span text jquery 
Javascript :: jquery addclass 
Javascript :: javascript how to increment by other than one in for loop 
Javascript :: Material-ui add alert icon 
Javascript :: javascript cancel timeout 
Javascript :: iterate through array js 
Javascript :: js get last element of array 
Javascript :: loop through array javascript 
Javascript :: format number with commas js 
Javascript :: express get query parameters 
Javascript :: reload react native app 
Javascript :: handlerbar console log 
Javascript :: angular cors issue 
Javascript :: display content in a modal react 
Javascript :: date add hours javascript 
Javascript :: import svg react 
Javascript :: discord.js remove every role a user has 
Javascript :: How to Use the toLowerCase() String Method in javascript 
Javascript :: javascript open pdf in new tab 
Javascript :: jest expect not contain 
Javascript :: Repeat a String Repeat a String 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =