0

currently im using jquery to get the URL path

 var href = document.location.pathname;

the path im looking for is something like /clients/invoice/details/DynamicID/DynamicID

i need to check if jquery if the href contains /clients/invoice/details/ in that order in the path to do something. Can someone please help me - i tried the following

       if(href.match('/\/clients/invoice/details/\/')) {

       }

but i think im doing something wrong.

Yeak
  • 2,470
  • 9
  • 45
  • 71

2 Answers2

4
var href = window.location.href;
if(href.indexOf(‘/clients/invoice/details/') > -1){
     //your code
}

You can do with a simple indexOf function instead of complex regex

Kshirodra Meher
  • 228
  • 1
  • 3
  • 11
0

You can use the includes() method.

if(href.includes('/clients/invoice/details/')) {

}

ref: includes()

zb22
  • 3,126
  • 3
  • 19
  • 34