0

This is almost embarrassing...almost because I'm just not seeing what I usually do.

I'm trying to execute a function in jquery in a Drupal site.

The function is:

    if ($('body').hasClass('.logged-in')) {
    $('ul.dropmenu').append('<li class="loggedInOverride">' + '<a href="/logout">' + 'Log out' + '</a>' + '</li>');
};

I have a new menu for a certain section of a website that is getting an entirely new theme and the current Primary navigation was built with older javascript and was a hornets nest to just restyle so I created a new menu, stuck it in a block and all is well except for the login/out behavior.

Since it's custom html/css/jquery and NOT a 'menu' within Drupal, the auto functionality of showing appropriate logout links isn't applicable here. Drupal 6.28 btw.

The statement works fine in firebugs console but I've tried this in a separate js file (other functions working so the file does load and there are no errors...other than not working!), I've tried sticking it at the bottom in my page.tpl.php file but the body is returned undefined even though the php is all processed first.

Where am I missing something here?

1 Answer 1

2

have you put this in a $(document).ready() container or in Drupal.behaviors.yourtheme ? If you dont, body isn't defined when this runs.

Sign up to request clarification or add additional context in comments.

2 Comments

yes, I have this function w/in the doc ready. The Drupal.behaviors kept throwing errors.
ok, the first thing is I removed the '.' before the class which is one thing I wasn't paying attention to and the second is that your post made me double check and I had actually put this test outside the final enclosing }); !...dangit, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.