SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery menu plugin messes up other jquery scripts

    I have the following jquery plugin that I use to create a menu system.

    jQuery.fn.initMenu = function() {

    return $(this).each(function() {
    var $menu = $(this);

    // Set the container's height
    $menu.find('.sub').show();
    $menu.parent().height($menu.height() + 10);
    $menu.find('.sub').hide();

    // Append arrow to submenu items
    $menu.find('li:has(ul)').each(function() {
    $(this).children('a').append("<span class='arrow'>&raquo;</span>");
    });
    $menu.find('.sub').hide();

    // The main part
    $menu.find('li a').click(function(e) {

    e.stopImmediatePropagation();
    var $submenu = $(this).next(), $this = $(this);

    if($menu.hasClass('noaccordion')) {
    if($submenu.length == 0) {
    window.location.href = this.href;
    }
    $submenu.slideToggle('normal');
    return false;
    } else {
    // Using accordeon
    if($submenu.hasClass('sub') && $submenu.is(':visible')) {
    // If already visible, slide up
    if($menu.hasClass('collapsible')) {
    $menu.find('.sub:visible').slideUp('normal');
    return false;
    }
    return false;
    } else if($submenu.hasClass('sub') && !$submenu.is(':visible')) {
    // If not visible, slide down
    $menu.find('.sub:visible').slideUp('normal');
    $submenu.slideDown('normal');
    return false;
    }
    }
    });

    });

    };

    The line of code
    return $(this).each(function() {
    messes up a couple of jquery scripts that I use. I think it is because many of the scripts are named function(). Does anyone know a way around this or can I alter this script so I do not have to use return $(this).each(function() {
    If I comment out this line of code the rest of my page works fine, but my menu is broken. thanks in advance.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by beckjoh View Post
    The line of code
    return $(this).each(function() {
    That is a fundamental part of jQuery that allows method chaining. It's something that virtually all jQuery plugins do.

    Show us a link to a version of your page that is misbehaving, and we'll work out what the real conflict is, and potentially even come up with a viable solution for you.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but I figured it out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •