Rash
Rash

Reputation: 896

check exact url using jquery if statements are dependent on whole url

I am using following code

if(window.location.href.indexOf("6-girl") > -1){

$("#something").show();

}

if(window.location.href.indexOf("6m") > -1){

$("#else").show();

}

Url from both the condition are different still the #something is showing on both pages.why? I am facing same problem with lot of url's. I want to show #something in only "6-girl" url and #else into "6m" only.

Upvotes: 0

Views: 358

Answers (1)

Ravi Gadag
Ravi Gadag

Reputation: 15861

try like this

var urlTocheck = window.location.href; 

var patternTocheck= /^(6-g)/ ;
var patternTocheckforMen= /^(6m)/ ;

if(patternTocheck.test(urlTocheck))
{
  show 6-girls part
}
else if(patternTocheckforMen.test(urlTocheck))
{
 //show 6m part
}
else
{
  //nothing matched
}

Demo : Regex Demo

Upvotes: 1

Related Questions