JQuery Child Selector vs. Find
Category:
So today I thought I knew enough about JQuery to easily add a click function to some unordered list menu items in a Drupal Panel... wrong.
Since Panels adds a bunch of its own divs inside the container div, this was not working:
$('div.my_panel > ul.menu > li').click(function () { alert('click'); } );
After a little experimenting, I realized the child selector doesn't work the way I thought. It is a "child" selector I guess, not a "grand child" selector. So instead I used the JQuery 'find' function.
This worked:
$('div.my_panel ').find('ul.menu > li').click(function () { alert('click'); } );
Lesson learned, I guess...