SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to collapse another items

    Hello,

    this code for tree category, i want when i click on item close another open items
    please help
    PHP Code:
    function loadLevel(id)
    {
        if ($(
    '#cat_'+id).attr('class').split(' ').indexOf('working') < 0)
        {
            if ($(
    '#cat_'+id).attr('class').split(' ').indexOf('expanded') < 0)
            {
                $(
    '#cat_loading_'+id).fadeIn('fast');
                $(
    '#cat_'+id).removeClass('cat_item_plus').addClass('cat_item_minus').addClass('working');
                        var 
    cc_chb_of cc_selected == true false;
                        var 
    xfix = $('#crossed_'+id).attr('checked') ? 'crossed_'+id false;
                        
    xajax_getCatLevel(idfalse'category_level_crossed.tpl''''crossed'cc_chb_ofxfix);
                        
    crossed_clear();
                    }
                    else
                    {
                        if ($(
    '#parent_'+id).css('display') == 'none')
                        {
                            $(
    '#parent_'+id).slideDown('slow');
                            $(
    '#cat_'+id).removeClass('cat_item_plus').addClass('cat_item_minus');
                        }
                        else
                        {
                            $(
    '#parent_'+id).slideUp('normal');
                            $(
    '#cat_'+id).removeClass('cat_item_minus').addClass('cat_item_plus');
                        }
                    }
                }
            } 

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what error messages are you getting?

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i didn't get any error message, its work fine, but this code its for tree menu when i click on item one its open the tree and when i click on another item its still open tree one and open tree two, what i want on click on another item hide all tree and open tree what i clicked.

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok.

    For me it's a lot easier and I would use less code by doing it with plain javascript, rather than with jquery. Hopefully someone else will come long if you must use jquery.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jone kent View Post
    i didn't get any error message, its work fine, but this code its for tree menu when i click on item one its open the tree and when i click on another item its still open tree one and open tree two, what i want on click on another item hide all tree and open tree what i clicked.
    The standard way to achieve this is to first close everything and then to open the one that was clicked.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    The standard way to achieve this is to first close everything and then to open the one that was clicked.
    Thanx for replay, so how to do this????

  7. #7
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jone kent View Post
    Thanx for replay, so how to do this????
    You can loop through all the elements first and set their display style to none and then set the display style of the clicked one to block.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    You can loop through all the elements first and set their display style to none and then set the display style of the clicked one to block.
    Bad webdev, he's using jQuery for his existing code so he might as well continue to benefit from the library that he's currently using.

    He can loop through all of the elements that have an id starting with "parent_"
    In that loop he can check if the element has a matching id number that was initially passed in, so that different behaviour can be performed with those that match.

    It might be something like this:

    Code javascript:
    $('[id^="parent_"]').each(function () {
        if (this.id.split('_')[1] == id) {
            // show this element
        } else {
            // hide this element
        }
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •