Find first link parent in navigation
<p>I try to select a link in a browser if this link is available in a sub-menu when I select the link with the parent class: hasSubMenu
My problem is that many links are selected when I do not want one...</p>

<pre><code>&lt;li style="z-index: 100;" class=""&gt;&lt;a href="/#" class="hasSubMenu" style="background: none repeat scroll 0pt 0pt rgba(114, 130, 143, 0.17); color: rgb(68, 68, 68);"&gt;A propos&lt;span class="subDown"&gt;&lt;/span&gt;&lt;/a&gt;&lt;ul class="sub-menu" style="top: 32px; visibility: visible; left: 0px; width: 187px; display: none;"&gt;&lt;li&gt;&lt;a href="/contactez_nous.php" style="background-color: rgb(248, 196, 96); text-shadow: none; margin: 0pt; text-decoration: none; padding-left: 6px;"&gt;Contact&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/page.php?4" style="padding-left: 6px;"&gt;Mentions légales&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/page.php?5" style="padding-left: 6px;"&gt;Partenaires&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul class="sub-menu" style="display: none; visibility: visible;"&gt;&lt;li&gt;&lt;a href="/contactez_nous.php" style="background-color: rgb(248, 196, 96); text-shadow: none; margin: 0pt; text-decoration: none;"&gt;Contact&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/page.php?4"&gt;Mentions légales&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/page.php?5"&gt;Partenaires&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
</code></pre>

<p>Jquery:</p>

<pre><code>var exploded = window.location.href.split('/');
// alert(exploded[3]);
$('ul.sub-menu li a').each(function(){
    var items = $(this).attr('href');
    var item_clean = items.substring(1, items.length);
    if(item_clean == exploded[3]){
        $(this).parents().find('a.hasSubMenu:first').attr('style','background: rgba(114, 130, 143, 0.17) none repeat scroll 0 0;color: #444444;');
        $(this).attr('style','background-color:#F8C460;text-shadow:none;margin:0;text-decoration:none;');
    }
});
</code></pre>

<p>Thx for your answers</p>
