Jquery, activate script if hashtag at end of url matches class name

Hi guys. I use a little jQuery to make my portfolio appear live when different categories are selected. Basically, the script matches the contents of the tag <li>on click (my menu) with the class names of other tags <li>elsewhere on the page. As a result, portfolio items matching the pressed navigation will be displayed and the rest will be removed. Live view. However, I want to add the ability to add a permalink to activate jquery to sort by hashtag at the end. For example: it work.html#category1will automatically install a script to hide everything except category 1. The following are the script and base page settings. Any help would be greatly appreciated!

 <script>
    $(document).ready(function() {
        $('#worknavwrap p a').click(function() {
            $(this).css('outline','none');
            $('ul#worknavwrap .current').removeClass('current');
            $(this).parent().addClass('current');

            var filterVal = $(this).text().toLowerCase().replace(' ','_');

            if(filterVal == 'all') {
                $('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
            } else {

                $('ul#portfolio li').each(function() {
                    if(!$(this).hasClass(filterVal)) {
                        $(this).fadeOut('normal').addClass('hidden');
                    } else {
                        $(this).fadeIn('slow').removeClass('hidden');
                    }
                });
            }

            return false;
        });
    });
    </script>
    <ul id="worknavwrap">
      <li><a href="#category1">Category 1</a></li>
      <li><a href="#category2">Category 2</a></li>
      <li><a href="#category3">Category 3</a></li>
    </ul>
    <ul id="portfolio">
      <li class="category1">Item 1</li>
      <li class="category1">Item 2</li>
      <li class="category2">Item 3</li>
      <li class="category1">Item 4</li>
      <li class="category3">Item 5</li>
      <li class="category3">Item 6</li>
      <li class="category2">Item 7</li>
      <li class="category1">Item 8</li>
    </ul>
+3
2

:

if(window.location.hash) {
    $('#worknavwrap a[href=' + window.location.hash + ']').click();
}

<a>, href, , .click().

<a>, :

<ul id="worknavwrap">
    <li><a id="category1" href="#category1">Category 1</a></li>
    <li><a id="category2" href="#category2">Category 2</a></li>
    <li><a id="category3" href="#category3">Category 3</a></li>
</ul>

, :

if(window.location.hash) {
    $(window.location.hash).click();
}

, , HTML, :

$('#worknavwrap li a').click(function() {...

:

$('#worknavwrap p a').click(function() {...

:

var filterVal = $(this).text().toLowerCase().replace(' ','');

:

var filterVal = $(this).text().toLowerCase().replace(' ','_');
+8

Source: https://habr.com/ru/post/1757021/