I have a problem which is driving me nuts. I'm a relative Javascript newbie so please be kind :).
I have some existing code for a left navigation menu that makes use of the Treeview plugin for jQuery (http://bassistance.de/jquery-plugins/jquery-plugin-treeview/). To quickly explain it, where a line item has more line items under it, a little div with an image (usually an arrow) will be appended to the line item and this little div is clickable to expand the line items under it.
That's all very good, however I wish to now ignore the small div and allow the user to click anywhere on the line item to expand the items under it.
A snippet of the code for the menu:
<div class="page-body-left" id="leftmenu">
<ul>
<li class="expandable" style="background-color: red;"><a class="createlink" href="link1">link1</a>
<ul style="display: none;">
<li><a class="createlink" href="link1a">link1a</a></li>
<li class="last"><a class="createlink" href="link1b">link1b</a></li>
</ul>
</li>
I added in this code to try and add the functionality I wanted into the document.ready function:
jQuery("#leftmenu ul > li.expandable").click(function () {
alert("Clicked!");
jQuery(this).children("ul").slideToggle("fast");
});
This worked fine in Firefox. However in both IE6 and IE7 nothing happens, not even the alert. However if you click on the link itself, the behaviour is correct (but of course aside from the fact that you are navigated away from the page).
Some things I've tried are:
- Wrapping the ul in divs to click on instead but didn't work.
- Adding "jQuery('#leftmenu ul > li.expandable').css('background-color','red');" works.
- Pulling the list out of the menu context did at least display the alert, but I want to avoid rewriting the wheel and want to reuse as much of the Treeview inserted classes as I can.
- Binding the click function to a standard div works.
Can someone see where I've gone wrong? Is Treeview messing with my click function? If so what is causing this?? It is so frustrating that it's working fine in Firefox and not IE!
Thanks, Jenny