The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
3 posters

    Show/hide script not working

    mremmet
    mremmet
    New Member


    Male Posts : 4
    Reputation : 1
    Language : English, Polish
    Location : Poland

    Solved Show/hide script not working

    Post by mremmet October 3rd 2015, 00:10

    Technical Details


    Forum version : #phpBB2
    Position : Founder
    Concerned browser(s) : Google Chrome
    Who the problem concerns : Yourself
    Forum link : ( link is hidden, you must reply to see )

    Description of problem

    Hi! My problem is (as topic said script I try to use on my forum. It's not workin of course.

    Here's my script
    Code:
    $(document).ready(function(){

        $("div.dropdown-link").click(function(e) {
          e.preventDefault();
          var $div = $(this).next('.dropdown-container');
          $(".dropdown-container").not($div).hide();
            if ($div.is(":visible")) {
                $div.hide()
            }  else {
              $div.show();
            }
        });

        $(document).click(function(e){
            var p = $(e.target).closest('.dropdown').length
            if (!p) {
                  $(".dropdown-container").hide();
            }
        });
       
    });
    HTML
    Code:
    <div class="dropdown"><div class="dropdown-link">Options</div><div class="dropdown-container" style="display: none;">Some text here</div></div><div class="dropdown"><div class="dropdown-link" >Options</div><div class="dropdown-container" style="display: none;">Some text here</div></div><div class="dropdown"><div class="dropdown-link">Options</div><div class="dropdown-container" style="display: none;">More words etc.</div></div>

    So, I'd like to know why it's not working on my forum while it's doing on jsfiddle. And it'd be great to get any tips what I can do to achieve similar effect.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: Show/hide script not working

    Post by Ange Tuteur October 3rd 2015, 11:35

    Hi @mremmet,

    When scripts are added to JS codes management they're automatically minified to remove a majority of the whitespace. Sometimes this can cause errors with scripts if they're missing a semicolon or two.

    I checked over the script and a semicolon is missing after this statement :
    Code:
    var p = $(e.target).closest('.dropdown').length

    Add a semicolon after that and it should work. Wink
    mremmet
    mremmet
    New Member


    Male Posts : 4
    Reputation : 1
    Language : English, Polish
    Location : Poland

    Solved Re: Show/hide script not working

    Post by mremmet October 3rd 2015, 13:49

    Thanks! It works very well.
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51498
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Show/hide script not working

    Post by SLGray October 3rd 2015, 20:43

    Topic solved and archived




    Show/hide script not working Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.

      Current date/time is September 22nd 2024, 19:35