Jquery selectors in Firefox not working

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

Question by:david_r_moore
  • 3

Expert Comment

ID: 23625476
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

ID: 23631334
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?


Author Comment

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

Accepted Solution

david_r_moore earned 0 total points
ID: 23670344
Apologies everyone.  My markup was wrong on my unordered list.  The script and CSS were correct all along.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
Following on from our article on "The Murky World of Consent and opt in", we thought we would issue some helpful guidance, not only on consent itself but knowing what information you are capturing, what you are doing with this data and how you can p…
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 site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 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