Jquery selectors in Firefox not working

Posted on 2009-02-12
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

Question by:david_r_moore
    LVL 2

    Expert Comment

    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(){

    Author Comment

    Hi, Thanks for taking a look.  You can see a working example here -  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?


    Author Comment

    Does anyone have any idea?  I dont understand why IE and Firefox are treating CSS selectors differently.  Please help.

    Accepted Solution

    Apologies everyone.  My markup was wrong on my unordered list.  The script and CSS were correct all along.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    Several part series to implement Internet Explorer 11 Enterprise Mode
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
    How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now