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.

Show/hide script not working

3 posters

Go down

Solved Show/hide script not working

Post by mremmet 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
mremmet
New Member

Male Posts : 4
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 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
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Show/hide script not working

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

Thanks! It works very well.
mremmet
mremmet
New Member

Male Posts : 4
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 October 3rd 2015, 7:43 pm

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.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51555
Reputation : 3524
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

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