User325313 User325313 - 3 months ago 8
Javascript Question

Show/Hide content by checking 2 differen URLS first

I'm running a code that displays content based on the url. If the user is in page X, the page displays the content number 1 and hides number 2, if he's in page Y, it displays the content number 2 and hides number 1. It works, but I would like to add a second URL to be checked.

My code is as follows:

jQuery(document).ready(function($){

var url = document.location.href;
if(url == "http://w.com/") {
$(".banner1").show();
$(".adsenselistingtop").show();
$("#leheaderbanner").hide();
$("#showhide-in-home").hide();

} else {
$(".banner1").hide();
$(".adsenselistingtop").hide();
$("#leheaderbanner").show();
$("#showhide-in-home").show();
}



});


I tried using something like this, but it didn't work:

if(url == "http://w.com/" && url == "http://w.com/index.php") {

Ish Ish
Answer

Use OR instead of AND as the URL can be either of them.

if(url == "http://w.com/" || url == "http://w.com/index.php") 
Comments