Hi,
I'm not sure why you are trying to override the click event - because
when you click on a menu item I'd expect a new page to load?

If you want to stop the new page loading, then you need to cancel the
default event for the <a> tag by adding return false,
    $(document).ready(function() {
        $("#menu a").click(function() {

            $(this).parents("li").addClass("active");
            return false;
        });
    });

I think what you want to do is to identify the menu item for the
current page when the page loads and add the 'active' class to it. Can
you post some sample html code.

Paul

On Nov 10, 8:45 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi, these are my first attempts with jQuery and I would be glad if
> somebody could help me.
>
> My Problem: I'm using the ASP.net MVC framework and wanted to keep
> track of the current clicked menu link. The menu links are in the
> master page and so is the jscript.
>
> What I tried to do is to attach some code to the click event of my
> links (in  a marked list) and attach a "selected" class to the current
> clicked link:
> sample code 1>>>
>
> i started with this little jquery script:
>     $(document).ready(function() {
>         $("#menu a").click(function() {
>
>             $(this).parents("li").addClass("active");
>         });
>     });
> <<<end sample code 1
>
> but soon found out that because the click function reloads the page it
> does apply the css right after the click but looses the class info
> after  the (other content's ) page recreation.
>
> I played around with storing the var outside the call but it always
> led to the result that all info is lost because I actually navigate to
> a new page.
>
> Finally I tried the approach below, where I use the ready function for
> the click event so that the page actually is done with the navigation
> but again I'll loose the context of the this function - although it
> should keep it when I read the documentation of chaining jQuery.... I
> already tried to return the element with this line "return $
> (this).parents.("li") inside of the click function but that does not
> work either. Can somebody help me please? Or is it not possible
> because of the actual navigation?
>
> sample code 2>>>
>
> $(document).ready(function() {
>     $("#menu a").click(function() {
>
>         }).ready(function() {
>
>             $(this).parents("li").addClass("active");
>             });
>     });
>
> <<<end sample code 2

Reply via email to