Highlight current page navigation link
<p>I've hardcoded a subnavigation and would like to highlight the navbar item of the current page by simply adding a class 'active' to those links. But the following HTML-Markup in combination with the javascript adds the active class to every li(.irp-menu-item)  and not just to the closest li. It would be necessary that the script only adds the class to the closest li and not to the other ones aswell, but somehow I am not able to solve this issue.</p>

<p>HTML-Markup:</p>

<pre><code>&lt;nav id="irp-subnav" class="css-sticky" role="navigation" aria-label="irp-subnav" lang="de-DE"&gt;
   &lt;div class="irp-wrapper"&gt;
        &lt;div class="irp-background"&gt;&lt;/div&gt;
        &lt;div class="irp-content"&gt;
            &lt;span class="irp-title"&gt;
                  TITLE&lt;/span&gt;
            &lt;div class="irp-menu"&gt;
            &lt;div class="irp-menu-tray"&gt;
                &lt;ul class="irp-menu-items"&gt;
                  &lt;li class="irp-menu-item"&gt;&lt;a href="/LINK-1/" class="irp-menu-link"&gt;LINK 1&lt;/a&gt;
                                                    &lt;/li&gt;
                  &lt;li class="irp-menu-item"&gt;&lt;a href="/LINK2/" class="irp-menu-link"&gt;LINK 2&lt;/a&gt;
                                                    &lt;/li&gt;
                  &lt;li class="irp-menu-item"&gt;&lt;a href="/LINK3/" class="irp-menu-link"&gt;LINK3&lt;/a&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
            &lt;div class="irp-actions irp-actions-right"&gt;
                &lt;div class="irp-action irp-action-menucta" aria-hidden="true"&gt;

                    &lt;label for="irp-menustate" class="irp-menucta"&gt; &lt;span class="irp-menucta-chevron"&gt;&lt;/span&gt;
                            &lt;/label&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/nav&gt;
</code></pre>

<p>Javascript:</p>

<pre><code>jQuery(document).ready(function($) {
$(function () {
var url = window.location.pathname; 
var activePage = url.substring(url.lastIndexOf('/') + 1); 
    $('.irp-menu-item .irp-menu-link').each(function () { 
        var linkPage = this.href.substring(this.href.lastIndexOf('/') + 1); 

        if (activePage == linkPage) { 
            $(this).closest("li").addClass("active"); 
        }
    });
})
});
</code></pre>