tags:

views:

1119

answers:

2

I've just upgraded to jQuery 1.3.2, which has mostly been fine, but I'm missing something when it comes to the new event model (I think)

$(document).ready(function()
{

    $(".AspNet-Menu-NonLink").click(function()
    {
        $(this).next($("ul")).slideToggle("fast");
    });
    $(".AspNet-Menu-NonLink").next($("ul")).hide();
    $(".AspNet-Menu-ChildSelected").next($("ul")).show();
});

This used to work, but the error "too much recursion" is popping out on this line:

$(".AspNet-Menu-NonLink").next($("ul")).hide();

How can this cause recursion, hide() hides something, what's to go wrong?

UPDATE

I've discovered that if I remove the references to jQuery UI 1.7.1 script library the problem goes away. Even if I'm not calling anything in the jQuery UI library, but have it included I get the error.

+6  A: 

For starters, try using

$(".AspNet-Menu-NonLink").next("ul").hide();

Instead.

Otherwise, you're implicitly searching for, and returning all ul elements on the page and then passing that massive result to the "next" function.

According to the documentation, 'next' takes a string, an expression, that is used to filter its traversal.

$("ul") however, executes a DOM query and returns a jQuery object.

Kent Fredric
That's helpful, I must have missunderstood the original docs.
ilivewithian
+4  A: 

Instead of this:

$(".AspNet-Menu-NonLink").next($("ul")).hide();

try this:

$(".AspNet-Menu-NonLink").next("ul").hide();

When calling next(), you only need to pass a CSS selector string, not an entire jQuery object. Documentation: http://docs.jquery.com/Traversing/next#expr

jQuery UI may be at fault because, when it's imported into your application, it overrides the standard jQuery hide() function. See line 3812 in the source: http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.js

Ron DeVera