Toggle up and down arrows as images












0















I have two images of arrows, up and down. My problem is when I use slideToggle(), it toggles up and down, but the image stays the same rather then changing. For instance, if I toggle up, the image should automatically change to the downward arrow and vice versa. Also, these arrows should be moved to the top of the page once the toggle happens. The current code displays two arrows, I would like that to be one arrow that changes based on the toggle.



What I have so far..



What I have



HTML:



 <div id="toggleParam">
<input type="image" class="upArrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
<input type="image" class="downArrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
</div>


CSS:



.upArrow{
display: block;
margin-left: 690px;
margin-top: 0px;
border-width: 5px;
padding-bottom: 0px;
cursor: pointer;
height: 7pt;
}
.downArrow{
display: block;
margin-left: 760px;
margin-right: 70px;
margin-top: -10px;
border-width: 5px;
padding-bottom: 0px;
cursor: pointer;
height: 7.5pt;
}


JavaScript/JQuery:



$(document).ready(function () {
$('#toggleParam').on("click", function () {
$('.dropdown').slideToggle();
});


What I need is shown in these two pictures..



What I want (upArrow)What I want (downArrow)



I realize missing a lot of code on the JS part.. I am working on it while asking this question. Thanks for the help!










share|improve this question





























    0















    I have two images of arrows, up and down. My problem is when I use slideToggle(), it toggles up and down, but the image stays the same rather then changing. For instance, if I toggle up, the image should automatically change to the downward arrow and vice versa. Also, these arrows should be moved to the top of the page once the toggle happens. The current code displays two arrows, I would like that to be one arrow that changes based on the toggle.



    What I have so far..



    What I have



    HTML:



     <div id="toggleParam">
    <input type="image" class="upArrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
    <input type="image" class="downArrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
    </div>


    CSS:



    .upArrow{
    display: block;
    margin-left: 690px;
    margin-top: 0px;
    border-width: 5px;
    padding-bottom: 0px;
    cursor: pointer;
    height: 7pt;
    }
    .downArrow{
    display: block;
    margin-left: 760px;
    margin-right: 70px;
    margin-top: -10px;
    border-width: 5px;
    padding-bottom: 0px;
    cursor: pointer;
    height: 7.5pt;
    }


    JavaScript/JQuery:



    $(document).ready(function () {
    $('#toggleParam').on("click", function () {
    $('.dropdown').slideToggle();
    });


    What I need is shown in these two pictures..



    What I want (upArrow)What I want (downArrow)



    I realize missing a lot of code on the JS part.. I am working on it while asking this question. Thanks for the help!










    share|improve this question



























      0












      0








      0








      I have two images of arrows, up and down. My problem is when I use slideToggle(), it toggles up and down, but the image stays the same rather then changing. For instance, if I toggle up, the image should automatically change to the downward arrow and vice versa. Also, these arrows should be moved to the top of the page once the toggle happens. The current code displays two arrows, I would like that to be one arrow that changes based on the toggle.



      What I have so far..



      What I have



      HTML:



       <div id="toggleParam">
      <input type="image" class="upArrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
      <input type="image" class="downArrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
      </div>


      CSS:



      .upArrow{
      display: block;
      margin-left: 690px;
      margin-top: 0px;
      border-width: 5px;
      padding-bottom: 0px;
      cursor: pointer;
      height: 7pt;
      }
      .downArrow{
      display: block;
      margin-left: 760px;
      margin-right: 70px;
      margin-top: -10px;
      border-width: 5px;
      padding-bottom: 0px;
      cursor: pointer;
      height: 7.5pt;
      }


      JavaScript/JQuery:



      $(document).ready(function () {
      $('#toggleParam').on("click", function () {
      $('.dropdown').slideToggle();
      });


      What I need is shown in these two pictures..



      What I want (upArrow)What I want (downArrow)



      I realize missing a lot of code on the JS part.. I am working on it while asking this question. Thanks for the help!










      share|improve this question
















      I have two images of arrows, up and down. My problem is when I use slideToggle(), it toggles up and down, but the image stays the same rather then changing. For instance, if I toggle up, the image should automatically change to the downward arrow and vice versa. Also, these arrows should be moved to the top of the page once the toggle happens. The current code displays two arrows, I would like that to be one arrow that changes based on the toggle.



      What I have so far..



      What I have



      HTML:



       <div id="toggleParam">
      <input type="image" class="upArrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
      <input type="image" class="downArrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
      </div>


      CSS:



      .upArrow{
      display: block;
      margin-left: 690px;
      margin-top: 0px;
      border-width: 5px;
      padding-bottom: 0px;
      cursor: pointer;
      height: 7pt;
      }
      .downArrow{
      display: block;
      margin-left: 760px;
      margin-right: 70px;
      margin-top: -10px;
      border-width: 5px;
      padding-bottom: 0px;
      cursor: pointer;
      height: 7.5pt;
      }


      JavaScript/JQuery:



      $(document).ready(function () {
      $('#toggleParam').on("click", function () {
      $('.dropdown').slideToggle();
      });


      What I need is shown in these two pictures..



      What I want (upArrow)What I want (downArrow)



      I realize missing a lot of code on the JS part.. I am working on it while asking this question. Thanks for the help!







      javascript jquery html css






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 20:50







      caitlinp

















      asked Nov 19 '18 at 20:43









      caitlinpcaitlinp

      677




      677
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You need to simple include the arrows' elements in the toggle function accordingly:



          $('#toggleParam').on("click", function () {
          $('.downArrow, .upArrow').toggle();
          $('.dropdown').slideToggle();
          });


          Also in the beginning you need to hide one of the arrows (not sure which one in your case):



          .downArrow{
          display: none;
          ...

          .upArrow{
          display: block;





          share|improve this answer
























          • This works great, but the strip (shown in the picture) doesn't slide up along with it.

            – caitlinp
            Nov 19 '18 at 21:28



















          0














          Try this (note - there's n-ways to do this; this is just how i'd do it).



              <!--index.html-->

          <div id="toggleParam" class="toggle-param--up">
          <input type="image" class="up-arrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
          <input type="image" class="down-arrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
          </div>


          /* app.css */
          .toggle-param--up .down-arrow { display; none;}
          .toggle-param--down .up-arrow { display; none;}


          //app.js

          $('#toggleParam').on("click", function (e) {

          // the rest of your logic goes here....


          var isUp = $(e.target).hasClass("toggle-param--up"),
          directionClass = { true: "toggle-param--up", false: "toggle-param--down"};
          $(e).target.removeClass(directionClass[isUp]).addClass(directionClass[!isUp];
          });





          share|improve this answer


























          • "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

            – caitlinp
            Nov 19 '18 at 21:30













          • Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

            – TuringCreep
            Nov 19 '18 at 21:35











          • This only toggles the picture.. the slider doesn't move up or down

            – caitlinp
            Nov 20 '18 at 14:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382362%2ftoggle-up-and-down-arrows-as-images%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You need to simple include the arrows' elements in the toggle function accordingly:



          $('#toggleParam').on("click", function () {
          $('.downArrow, .upArrow').toggle();
          $('.dropdown').slideToggle();
          });


          Also in the beginning you need to hide one of the arrows (not sure which one in your case):



          .downArrow{
          display: none;
          ...

          .upArrow{
          display: block;





          share|improve this answer
























          • This works great, but the strip (shown in the picture) doesn't slide up along with it.

            – caitlinp
            Nov 19 '18 at 21:28
















          0














          You need to simple include the arrows' elements in the toggle function accordingly:



          $('#toggleParam').on("click", function () {
          $('.downArrow, .upArrow').toggle();
          $('.dropdown').slideToggle();
          });


          Also in the beginning you need to hide one of the arrows (not sure which one in your case):



          .downArrow{
          display: none;
          ...

          .upArrow{
          display: block;





          share|improve this answer
























          • This works great, but the strip (shown in the picture) doesn't slide up along with it.

            – caitlinp
            Nov 19 '18 at 21:28














          0












          0








          0







          You need to simple include the arrows' elements in the toggle function accordingly:



          $('#toggleParam').on("click", function () {
          $('.downArrow, .upArrow').toggle();
          $('.dropdown').slideToggle();
          });


          Also in the beginning you need to hide one of the arrows (not sure which one in your case):



          .downArrow{
          display: none;
          ...

          .upArrow{
          display: block;





          share|improve this answer













          You need to simple include the arrows' elements in the toggle function accordingly:



          $('#toggleParam').on("click", function () {
          $('.downArrow, .upArrow').toggle();
          $('.dropdown').slideToggle();
          });


          Also in the beginning you need to hide one of the arrows (not sure which one in your case):



          .downArrow{
          display: none;
          ...

          .upArrow{
          display: block;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 20:58









          Velimir TchatchevskyVelimir Tchatchevsky

          2,17411118




          2,17411118













          • This works great, but the strip (shown in the picture) doesn't slide up along with it.

            – caitlinp
            Nov 19 '18 at 21:28



















          • This works great, but the strip (shown in the picture) doesn't slide up along with it.

            – caitlinp
            Nov 19 '18 at 21:28

















          This works great, but the strip (shown in the picture) doesn't slide up along with it.

          – caitlinp
          Nov 19 '18 at 21:28





          This works great, but the strip (shown in the picture) doesn't slide up along with it.

          – caitlinp
          Nov 19 '18 at 21:28













          0














          Try this (note - there's n-ways to do this; this is just how i'd do it).



              <!--index.html-->

          <div id="toggleParam" class="toggle-param--up">
          <input type="image" class="up-arrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
          <input type="image" class="down-arrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
          </div>


          /* app.css */
          .toggle-param--up .down-arrow { display; none;}
          .toggle-param--down .up-arrow { display; none;}


          //app.js

          $('#toggleParam').on("click", function (e) {

          // the rest of your logic goes here....


          var isUp = $(e.target).hasClass("toggle-param--up"),
          directionClass = { true: "toggle-param--up", false: "toggle-param--down"};
          $(e).target.removeClass(directionClass[isUp]).addClass(directionClass[!isUp];
          });





          share|improve this answer


























          • "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

            – caitlinp
            Nov 19 '18 at 21:30













          • Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

            – TuringCreep
            Nov 19 '18 at 21:35











          • This only toggles the picture.. the slider doesn't move up or down

            – caitlinp
            Nov 20 '18 at 14:24
















          0














          Try this (note - there's n-ways to do this; this is just how i'd do it).



              <!--index.html-->

          <div id="toggleParam" class="toggle-param--up">
          <input type="image" class="up-arrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
          <input type="image" class="down-arrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
          </div>


          /* app.css */
          .toggle-param--up .down-arrow { display; none;}
          .toggle-param--down .up-arrow { display; none;}


          //app.js

          $('#toggleParam').on("click", function (e) {

          // the rest of your logic goes here....


          var isUp = $(e.target).hasClass("toggle-param--up"),
          directionClass = { true: "toggle-param--up", false: "toggle-param--down"};
          $(e).target.removeClass(directionClass[isUp]).addClass(directionClass[!isUp];
          });





          share|improve this answer


























          • "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

            – caitlinp
            Nov 19 '18 at 21:30













          • Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

            – TuringCreep
            Nov 19 '18 at 21:35











          • This only toggles the picture.. the slider doesn't move up or down

            – caitlinp
            Nov 20 '18 at 14:24














          0












          0








          0







          Try this (note - there's n-ways to do this; this is just how i'd do it).



              <!--index.html-->

          <div id="toggleParam" class="toggle-param--up">
          <input type="image" class="up-arrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
          <input type="image" class="down-arrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
          </div>


          /* app.css */
          .toggle-param--up .down-arrow { display; none;}
          .toggle-param--down .up-arrow { display; none;}


          //app.js

          $('#toggleParam').on("click", function (e) {

          // the rest of your logic goes here....


          var isUp = $(e.target).hasClass("toggle-param--up"),
          directionClass = { true: "toggle-param--up", false: "toggle-param--down"};
          $(e).target.removeClass(directionClass[isUp]).addClass(directionClass[!isUp];
          });





          share|improve this answer















          Try this (note - there's n-ways to do this; this is just how i'd do it).



              <!--index.html-->

          <div id="toggleParam" class="toggle-param--up">
          <input type="image" class="up-arrow" src="~/Content/Images/Reserved.ReportViewerWebControl.png" name="Show / Hide Parameters" />
          <input type="image" class="down-arrow" src="~/Content/Images/downArrow.png" name="Show / Hide Parameters" />
          </div>


          /* app.css */
          .toggle-param--up .down-arrow { display; none;}
          .toggle-param--down .up-arrow { display; none;}


          //app.js

          $('#toggleParam').on("click", function (e) {

          // the rest of your logic goes here....


          var isUp = $(e.target).hasClass("toggle-param--up"),
          directionClass = { true: "toggle-param--up", false: "toggle-param--down"};
          $(e).target.removeClass(directionClass[isUp]).addClass(directionClass[!isUp];
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 21:36

























          answered Nov 19 '18 at 21:12









          TuringCreepTuringCreep

          365




          365













          • "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

            – caitlinp
            Nov 19 '18 at 21:30













          • Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

            – TuringCreep
            Nov 19 '18 at 21:35











          • This only toggles the picture.. the slider doesn't move up or down

            – caitlinp
            Nov 20 '18 at 14:24



















          • "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

            – caitlinp
            Nov 19 '18 at 21:30













          • Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

            – TuringCreep
            Nov 19 '18 at 21:35











          • This only toggles the picture.. the slider doesn't move up or down

            – caitlinp
            Nov 20 '18 at 14:24

















          "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

          – caitlinp
          Nov 19 '18 at 21:30







          "Uncaught TypeError: Cannot read property 'hasClass' of undefined"

          – caitlinp
          Nov 19 '18 at 21:30















          Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

          – TuringCreep
          Nov 19 '18 at 21:35





          Woops. We should use $(e.target) instead of $(e).target. Lemme improve my answer.

          – TuringCreep
          Nov 19 '18 at 21:35













          This only toggles the picture.. the slider doesn't move up or down

          – caitlinp
          Nov 20 '18 at 14:24





          This only toggles the picture.. the slider doesn't move up or down

          – caitlinp
          Nov 20 '18 at 14:24


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382362%2ftoggle-up-and-down-arrows-as-images%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?