[jQuery] Re: Selectors with :has and with variables
I owe you an apology, Hector - I'd been looking at the same lines for so long, I'd stopped seeing what I'd written ... and was doubling-up my selector. This DOES work: $( '#themenu' ).children( 'li[id]' ).hover( function() { var theID = $(this).attr('id'); $( # + theID + ul ).toggle() ; }); Thank you very much! Cherry. On Nov 7, 12:27 am, Hector Virgen [EMAIL PROTECTED] wrote: Maybe this: $( '#cat [ + theID + ] ul' ).toggle() ; Should be like this? $( #cat # + theID + ul ).toggle() ; -Hector On Thu, Nov 6, 2008 at 4:14 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have read the other threads on this topic, but am still getting nowhere ... I'm trying to make a simple (haha) show-hide menu. The first last menu items are static - and don't have IDs. I need to select them out, otherwise I get a g is undefined error. Problem 1: The initial selection doesn't work $( '#themenu' ).children( 'li:has(id)' ).hover( function() { alert ( 'Got an id!' ); }); What have I done wrong? Problem 2: Getting the relevant var into my toggle statement. This works: $( '#cat2 ul' ).toggle() ; This doesn't work: $( this.hash ).children( 'ul' ).toggle() ; This doesn't work, either: var theID = $(this).attr('id'); $( '#cat [ + theID + ] ul' ).toggle() ; I'm at my wits' end, and desperate for your insights
[jQuery] Re: Selectors with :has and with variables
Having - finally! - finished this, I thought I'd post my code. I'm very sure it could be more compact, but I'm a bit of a Javascript dork and thought others might benefit from my step-by-step approach ;) // menu show/hide $( '#themenu' ).children( 'li[id]' ).hover( function() { var theID = $( this ).attr( 'id' ); var theSiblings = $( this ).siblings() ; // second level var theList = # + theID + ul:first ; $( theList ).slideToggle( 'slow' ); $( theSiblings ).children( 'ul' ).hide() ; // third level var theSub = $( theList ).children( 'li' ) ; $( theSub ).hover( function() { var theSubSibs = $( this ).siblings() ; $( this ).children( 'ul' ).fadeIn( 'slow' ) ; $( theSubSibs ).children( 'ul' ).fadeOut( 'fast' ) ; }); }, function() { $( this ).children( 'ul' ).hide( 'slow' ) ; }); Cherry.
[jQuery] Re: Selectors with :has and with variables
You don't want :has you want a normal attribute selector. $( '#themenu' ).children( 'li[id]' ) Karl Rudd On Fri, Nov 7, 2008 at 11:14 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have read the other threads on this topic, but am still getting nowhere ... I'm trying to make a simple (haha) show-hide menu. The first last menu items are static - and don't have IDs. I need to select them out, otherwise I get a g is undefined error. Problem 1: The initial selection doesn't work $( '#themenu' ).children( 'li:has(id)' ).hover( function() { alert ( 'Got an id!' ); }); What have I done wrong? Problem 2: Getting the relevant var into my toggle statement. This works: $( '#cat2 ul' ).toggle() ; This doesn't work: $( this.hash ).children( 'ul' ).toggle() ; This doesn't work, either: var theID = $(this).attr('id'); $( '#cat [ + theID + ] ul' ).toggle() ; I'm at my wits' end, and desperate for your insights
[jQuery] Re: Selectors with :has and with variables
Maybe this: $( '#cat [ + theID + ] ul' ).toggle() ; Should be like this? $( #cat # + theID + ul ).toggle() ; -Hector On Thu, Nov 6, 2008 at 4:14 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have read the other threads on this topic, but am still getting nowhere ... I'm trying to make a simple (haha) show-hide menu. The first last menu items are static - and don't have IDs. I need to select them out, otherwise I get a g is undefined error. Problem 1: The initial selection doesn't work $( '#themenu' ).children( 'li:has(id)' ).hover( function() { alert ( 'Got an id!' ); }); What have I done wrong? Problem 2: Getting the relevant var into my toggle statement. This works: $( '#cat2 ul' ).toggle() ; This doesn't work: $( this.hash ).children( 'ul' ).toggle() ; This doesn't work, either: var theID = $(this).attr('id'); $( '#cat [ + theID + ] ul' ).toggle() ; I'm at my wits' end, and desperate for your insights
[jQuery] Re: Selectors with :has and with variables
Karl, thank you SO much for that! At least I can now be sure my toggle thing isn't failing because of the g error :)) Cherry. On Nov 7, 12:26 am, Karl Rudd [EMAIL PROTECTED] wrote: You don't want :has you want a normal attribute selector. $( '#themenu' ).children( 'li[id]' ) Karl Rudd On Fri, Nov 7, 2008 at 11:14 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have read the other threads on this topic, but am still getting nowhere ... I'm trying to make a simple (haha) show-hide menu. The first last menu items are static - and don't have IDs. I need to select them out, otherwise I get a g is undefined error. Problem 1: The initial selection doesn't work $( '#themenu' ).children( 'li:has(id)' ).hover( function() { alert ( 'Got an id!' ); }); What have I done wrong? Problem 2: Getting the relevant var into my toggle statement. This works: $( '#cat2 ul' ).toggle() ; This doesn't work: $( this.hash ).children( 'ul' ).toggle() ; This doesn't work, either: var theID = $(this).attr('id'); $( '#cat [ + theID + ] ul' ).toggle() ; I'm at my wits' end, and desperate for your insights
[jQuery] Re: Selectors with :has and with variables
Thank you, Hector, but there's still nothing happening . Any other clues? (My grandmother and firstborn are now on offer) Cherry On Nov 7, 12:27 am, Hector Virgen [EMAIL PROTECTED] wrote: Maybe this: $( '#cat [ + theID + ] ul' ).toggle() ; Should be like this? $( #cat # + theID + ul ).toggle() ; -Hector On Thu, Nov 6, 2008 at 4:14 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have read the other threads on this topic, but am still getting nowhere ... I'm trying to make a simple (haha) show-hide menu. The first last menu items are static - and don't have IDs. I need to select them out, otherwise I get a g is undefined error. Problem 1: The initial selection doesn't work $( '#themenu' ).children( 'li:has(id)' ).hover( function() { alert ( 'Got an id!' ); }); What have I done wrong? Problem 2: Getting the relevant var into my toggle statement. This works: $( '#cat2 ul' ).toggle() ; This doesn't work: $( this.hash ).children( 'ul' ).toggle() ; This doesn't work, either: var theID = $(this).attr('id'); $( '#cat [ + theID + ] ul' ).toggle() ; I'm at my wits' end, and desperate for your insights