jquery how to check if url contains word?
javascript, jquery
Solution
Try:
if (window.location.href.indexOf("catalogue") > -1) { // etc
indexOf doesn't return true/false, it returns the location of the search string in the string; or -1 if not found.
Problem
I want to be able to check if url contains the word catalogue. This is what i am trying... ``` $(document).ready(function () { if (window.location.href.indexOf("catalogue")) { $("#trail").toggle(); } }); ``` The url of the site could be.. ``` http://site.co.uk/catalogue/ ``` Or ``` http://site.co.uk/catalogue/2/domestic-rainwater.html ``` etc. But it doesn't work. Can somebody please point out where I'm going wrong?