rklitz
rklitz

Reputation: 162

Hiding Content Based on Content of URL String

I am trying to hide a certain fieldset with an id of "retail" based on if the URL has 'studio' as a part of it. The URL would read as follows:

/island-careers/studio/accounting/accountant/apply.html

Here is my script I have written up but I can't seem to get it to recognize if 'studio' is in the URL.

<script>
    jQuery(document).ready(function(){

        var path = window.location.pathname;

        console.log(path);

        var split = window.location.href.split('/');

        console.log(split);

        console.log(split[4]);

      if (split[4] === 'studio') {
          jQuery('#retail').css('display, none');
      }  
    });
</script>

The "console.log(split[4]); was to find the location of 'studio' in the array. There must be something wrong with my IF statement I guess. I also tried this method but it didn't work for me either:

<script>
    jQuery(document).ready(function(){

        var path = window.location.pathname;

        console.log(path);


      if (path.indexOf('studio') >= 0) {
          jQuery('#retail').css('display, none')
      }  
    });
</script>

Upvotes: 0

Views: 964

Answers (1)

Josh KG
Josh KG

Reputation: 5150

Your jQuery line to change the CSS should be:

 jQuery('#retail').css('display', 'none');

Upvotes: 4

Related Questions