I have a working code that would hide/show content based on the URL value. example:
www.domain.com/?filter_brands=gucci
will show content that's meant for 'gucci', the rest will remain hidden.
However, if the url gets additional fields/values it stops working.. Example:
www.domain.com/?filter_brands=gucci&query_type_brands=or
does not work.. What do I change in javascript so it reads the first filter_brands value and ignores the rest..? Thanks a lot guys!
Here is the javascript:
$(document).ready(function() {
var brands = 'gucci';
var url = window.location.search;
brands = url.match(/filter_brands=(.*)/)[1];
showDiv(brands);
});
function showDiv(brands) {
$('.boxes').hide();
$('#' + brands).show();
}
Here is the html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div class="boxes" id="gucci">Gucci is awesome!</div>
<div class="boxes" id="versace">Versace is da bomb!</div>
<div class="boxes" id="dolce-gabanna">Dolce & Gabanna is cool!</div>
</body>
</html>
Here is my the full code on fiddle http://jsfiddle.net/s7V26/
It doesn't hide content on fiddle, because you need to load url with ?filter_brands=gucci but the code works..