Help with css selector for jquery
- by NachoF
I have this wordpress blog that has many pages with subpages that dropdown on hover.... the thing is, I dont want the pages that you hover to link to anything unless they dont have any ul with many anchors inside so just the subpages will have a href different than "#"
So basically Im hacking my way through this with some simple javascript.
jQuery(document).ready(function(){
jQuery("#menus li > a").attr("href","#");
});
This is selecting every a.. and I dont want that... I just want the anchors that are main pages, not subpages... heres the html so maybe you can think of a better way to select this.
Ill explain first
the structure is
an ul with many li that have an anchor inside
if the li also has a ul inside then those are subpages that will appear on hover.
hence the initial anchor should have href="#"
if there is no ul inside the li then the li a should keep its href.
<ul id="menus">
<li>
<a href="somelink">Main Page</a> //href should be changed to #
<ul>
<li>
<a href="somelink2/">Subpage1</a>
</li>
<li>
<a href="somelink3">Subpage2</a>
</li>
</ul>
</li>
<li>
<a href="somelink">MainPage-with-no-subpages</a> //href should not be changed
</li>
<li>
<a href="somelink4">MainPage</a> //href should be changed to #
<ul>
<li>
<a href="somelink5">Subpage</a>
</li>
<li>
<a href="somelink6">Subpage</a>
</li>
</ul>
</li>
</ul>