The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Show/hide script not working

View previous topic View next topic Go down

Solved Show/hide script not working

Post by mremmet on October 2nd 2015, 11:10 pm

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.

mremmet
New Member

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

http://erised.fairtopic.com

Back to top Go down

Solved Re: Show/hide script not working

Post by Ange Tuteur on October 3rd 2015, 10:35 am

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

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Show/hide script not working

Post by mremmet on October 3rd 2015, 12:49 pm

Thanks! It works very well.

mremmet
New Member

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

http://erised.fairtopic.com

Back to top Go down

Solved Re: Show/hide script not working

Post by SLGray on October 3rd 2015, 7:43 pm

Topic solved and archived



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


SLGray
Administrator
Administrator

Male Posts : 36697
Reputation : 2445
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum