views:

30

answers:

2

I am trying to initiate a function when a click event happens on a link within a list. This is for a menu.

Right now, I have this and it works:

$(".left-navigation-holder li a:has(~ul)").click(toggleMenu);

Basically, the click event initiate toggleMenu if the link clicked has a list (ul) down the tree. Now, I would also have this to happen only if that link href attribute is equal to nothing. I am trying this but doesnt work:

$(".left-navigation-holder li a.attr(href=''):has(~ul)").click(toggleMenu);

Any help would be much appreciated, thank you.

A: 

Try:

$(".left-navigation-holder ul").parent("li a[href='']").click(toggleMenu)

You can't embed the attr method inside the selector string.

kingjeffrey
This one works great also, thank you.
Ben
sorry it does not, the first solution above does.I thought I saw this a few minutes ago:$(".left-navigation-holder li a[href='']:has(~ul)").click(toggleMenu);And that worked well
Ben
I had assumed from your original question that you had nested the <ul> inside the <a>. It didn't make sense to me why you would do that, but that is what is implied. This script will work for that assumption, but, if the <ul> is a sibling to the <a> (which makes more sense), Reigel's script above will work.
kingjeffrey
A: 

try

$(".left-navigation-holder li ul").closest("li").find("a[href='']").click(toggleMenu)
Reigel
Works great, thank you. This site rocks.
Ben