Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    Toggle with JavaScript code

    General Discussion
    2
    6
    326
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      Ed Low last edited by

      Re: Dropdown menu

      Hello! I have this following content that I would like to change into toggle menu. For example, I click on "Filming & Photography" and the smaller paragraph below it will show up, and click again to make it disappear

      c816d334-b972-4701-a7eb-c8ea07fab9e3-image.png

      I have tried adding "id" attributes to each part of the content, and put JavaScript code embed block to after the footer of the page, but it doesn't work. May I know if there's a way to do it please? Thank you

      1 Reply Last reply Reply Quote 0
      • Wassim
        Wassim last edited by

        Hello,

        Can you share a link to the page to know in what part of your website it is located? And what resolution (desktop, mobile)?

        1 Reply Last reply Reply Quote 0
        • E
          Ed Low last edited by

          Hi, the URL is https://www.1010media.sg/index.html. I want to implement it for the desktop version

          Thank you!

          1 Reply Last reply Reply Quote 0
          • Wassim
            Wassim last edited by

            Ok, can you show up the JS you tried to apply?
            Your logic with the id should work fine.

            1 Reply Last reply Reply Quote 0
            • E
              Ed Low last edited by Ed Low

              Sure!

              The JS code

              <script>
                  //Type or paste your javascript code here
                  function clickToggle() {
                      var service1Sub = document.getElementById("service1-sub");
                      if (service1Sub.style.display === "none") {
                          service1Sub.style.display = "block";
                      } else {
                          service1Sub.style.display = "none";
                      }
                  }
              </script>
              

              Currently pasted below the footer
              5c496d59-e8fe-4f03-9a48-b7b7dd32f8ad-image.png

              HTML code

              <h1 class="appdrag-element dynamic-sized-element service1 ui-draggable-handle resizable-elem" style="position:relative;margin-bottom:0 !important;margin-top:0 !important;padding:0 0 0 10px !important" category="Texts" margin-desktop-bottom="0" padding-desktop-top="0" padding-desktop-bottom="0" padding-desktop-left="10" padding-desktop-right="0" market-id="3700128" owner-id="4" autocomplete="off" id="service1" onclick="clickToggle()">
                <span style=" font-family:playfair=&quot;&quot; "><span style="font-size:20px">Filming &amp; Photography</span></span>
              </h1>
              
              <p style="position:relative;text-align:left !important;padding-left:30px !important;margin-top:0 !important;margin-bottom:0 !important" market-id="3700137" owner-id="4" class="dynamic-sized-element service1-sub ui-draggable-handle resizable-elem" padding-desktop-left="30" padding-desktop-top="NaN" padding-desktop-bottom="NaN" padding-desktop-right="NaN" autocomplete="off" id="service1-sub">
                                Instructional Videos
                                <br>
                                 Documentary Filming
                                <br>
                                 Green Screen
                                <br>
                                 Underwater Filming
                              </p>
              

              For this part
              3b5e1586-2f61-4884-980a-3ccc2a7aca99-image.png

              Thank you Wassim!

              1 Reply Last reply Reply Quote 0
              • Wassim
                Wassim last edited by

                @Ed-Low said in Toggle with JavaScript code:

                var service1Sub = document.getElementById("service1-sub");
                if (service1Sub.style.display === "none") {
                service1Sub.style.display = "block";
                } else {
                service1Sub.style.display = "none";
                }

                Did you change anything between your answer and now? It works well on my end now.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post