We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Jquery selectors in Firefox not working

Medium Priority
Last Modified: 2013-12-07
Hello Experts, I hope you can help.  I have a menu made from an unordered list and CSS and Jquery.  In IE7 the menu works perfectly but in Firefox 1, 2 and 3, the .hide() function does not work and neither does $this.siblings("ul").show(); or  $(this).parents("ul").show();.  Adding the class to the clicked <a> does work however.  I cant work out why the selectors are functioning correctly in Firefox.  Does any one have a suggestion?  Many thanks.
<script>jQuery(function($) {
 $('#navMenu li ul').hide();
   $("#navMenu ul a").each(function(){
	var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
var href = this.getAttribute('href',2);
        if ( sPage == href) {
<div id="navMenu">
	<li><a id="Home" href="index.asp">Home</a></li>
	<li><a id="NavCompany" href="company.asp">The Company</a></li>
	<li><a id="NavWhatsIncluded" href="whatsIncluded.asp">General</a></li>
	<li><a id="Minibus" href="products.asp">Products</a></li>
		<li><a id="Minibus" href="renault.asp">Renault</a></li>
			<li><a id="RenaultMaster" href="renaultmaster.asp">Master</a></li>
				<li><a id="RenaultMasterL1H1" href="renaultmasterL1H1.asp">L1 H1</a></li>
				<li><a id="RenaultMasterL1H2" href="renaultmasterL1H2.asp">L1 H2</a></li>
				<li><a id="RenaultMasterL2H2" href="renaultmasterL2H2.asp">L2 H2</a></li>
				<li><a id="RenaultMasterL2H3" href="renaultmasterL2H3.asp">L2 H3</a></li>
				<li><a id="RenaultMasterL3H2" href="renaultmasterL3H2.asp">L3 H2</a></li>
				<li><a id="RenaultMasterL3H3" href="renaultmasterL3H3.asp">L3 H3</a></li>
				</ul><!-- End Renault Master-->
			<li><a id="RenaultTrafic" href="renaultTrafic.asp">Trafic</a></li>
				<li><a id="RenaultTraficL1H1" href="renaultTraficL1H1.asp">L1 H1</a></li>
   				<li><a id="RenaultTraficL1H2" href="renaultTraficL1H2.asp">L1 H2</a> </li>
    				<li><a id="RenaultTraficL2H2" href="renaultTraficL2H1.asp">L2 H1</a> </li>
    				<li><a id="RenaultTraficL2H3" href="renaultTraficL2H2.asp">L2 H2</a></li>
				</ul><!-- End Renault Trafic--> 
			</ul><!-- End Renault-->
		<li><a id="Minibus" href="Volkswagen.asp">Volkswagen</a></li></ul><!-- End Volkswagen-->
	</ul><!-- End Products-->
    	<li><a href="schools.asp">Schools</a></li>
    	<li><a href="cars.asp">Cars</a></li>
    	<li><a href="stocklist.asp">Stock</a></li>
    	<li><a href="contracthire.asp">Contract hire</a></li>
	<li><a href="spareparts.asp">Spare Parts</a></li>
	<li><a href="links.asp">Links</a></li>
</ul><!-- End Menu-->

Open in new window

Watch Question

can you please explain what you want to hide first

$('#navMenu ul li').hide();

instead of

 $('#navMenu li ul').hide();

li is son of ul and can't be selected by calling it first

also there is nothing called (ul a)
it must be (ul li a ) instead of :

 $("#navMenu ul a").each(function(){


 $("#navMenu ul li a").each(function(){


Hi, Thanks for taking a look.  You can see a working example here - www.minibusoptions.co.uk/test/index.asp  If you click on Minibus on the menu, the menu expands to show the options under minibus.  If you click Renault, you will then see more options.  This works fine in IE but not firefox.  If I change it to $('#navMenu ul li').hide(); the whole menu is hidden, I only want to hide any submenu items.  $("#navMenu ul a").each(function(){ then checks each <a> to see which one should be active and shows any siblings.  Firefox does change the class of the selected item to Active, so the function is working. However $(this).siblings("ul").show() and $(this).parents("ul").show(); dont seem to work in Firefox.  Any more ideas?


Does anyone have any idea?  I dont understand why IE and Firefox are treating CSS selectors differently.  Please help.
Apologies everyone.  My markup was wrong on my unordered list.  The script and CSS were correct all along.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.