Add Class to element according to pathname

113 views Asked by At

This script works great for adding the class "criminal" to the div named "h1_wrapper" for this page:

if(window.location.pathname == '/Criminal-Law-Blog') {$( ".h1_wrapper" ).addClass( "criminal" );

When I click into a specific blog entry, it adds to the pathname; for example:

/Criminal-Law-Blog/2014/11/Criminal-Law-Blog-Test-Entry-1

How do I edit the code to make it so that the class is added to any path that follows "/Criminal-Law-Blog"? I know it's probably easy, but I just can't figure it out!

Thanks in advance!

1

There are 1 answers

0
Tal On BEST ANSWER

The simplest way is to do window.location.pathname.match(/^\/Criminal-Law-Blog/)