Jquery selectors in Firefox not working

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) {
	$(this).addClass("active");
	$(this).siblings("ul").show();
                     $(this).parents("ul").show();
	  }
    });	
});
</script>
 
<div id="navMenu">
<ul>
	<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>
	<ul>
		<li><a id="Minibus" href="renault.asp">Renault</a></li>
			<ul>
			<li><a id="RenaultMaster" href="renaultmaster.asp">Master</a></li>
				<ul>
				<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>
				<ul>
				<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-->
</div>

Open in new window

david_r_mooreAsked:
Who is Participating?
 
david_r_mooreConnect With a Mentor Author Commented:
Apologies everyone.  My markup was wrong on my unordered list.  The script and CSS were correct all along.
0
 
basselkhCommented:
can you please explain what you want to hide first
try:

$('#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(){

try:

 $("#navMenu ul li a").each(function(){
0
 
david_r_mooreAuthor Commented:
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?

0
 
david_r_mooreAuthor Commented:
Does anyone have any idea?  I dont understand why IE and Firefox are treating CSS selectors differently.  Please help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.