Javascript get css height proprietyHow do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?Change an HTML5 input's placeholder color with CSSHow do I remove a particular element from an array in JavaScript?Is it possible to apply CSS to half of a character?

why it is 2>&1 and not 2>>&1 to append to a log file

Explaining intravenous drug abuse to a small child

If studying in groups is more effective, why don't academics also research in groups?

When does WordPress.org notify sites of new version?

Why is the episode called "The Last of the Starks"?

Make me a minimum magic sum

Can I use LPGL3 for library and Apache 2 for "main()"?

Displaying an Estimated Execution Plan generates CXPACKET, PAGELATCH_SH, and LATCH_EX [ACCESS_METHODS_DATASET_PARENT] waits

Convert Numbers To Emoji Math

What detail can Hubble see on Mars?

When will the number of stars be a maximum?

How can I finally understand the confusing modal verb "мочь"?

GitLab account hacked and repo wiped

Why can’t you see at the start of the Big Bang?

Drug Testing and Prescribed Medications

Why doesn't a particle exert force on itself?

Select list elements based on other list

Clauses with 3 infinitives at the end

Is there a reason why Turkey took the Balkan territories of the Ottoman Empire, instead of Greece or another of the Balkan states?

Can anyone identify this unknown 1988 PC card from The Palantir Corporation?

Is there any optimization for thread safety in for loop of Java?

What's the role of the Receiver/Transmitter in Avengers Endgame?

How do I give a darkroom course without negs from the attendees?

The unknown and unexplained in science fiction



Javascript get css height propriety


How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?Change an HTML5 input's placeholder color with CSSHow do I remove a particular element from an array in JavaScript?Is it possible to apply CSS to half of a character?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have this CSS transition effect menu that is activated with a Javascript function through the click event on a button. However, I need the same button to hide the menu if it is visible.



I tried doing this by getting the same property that is changed by the function, as follows:



if (menu01.style.maxHeight == '0px')
menu01.style.maxHeight = '600px';
else
menu01.style.maxHeight = '0px';


However, as it may seem perfectly logical, IT DOES NOT WORK, and in addition it locks the function.
A GLOBAL variable could solve the problem, but they say we should avoid globals because of security.



<style type="text/css">
#menu01
display: block;
position: absolute;
top:0px;
left: 130px;
width: 120px;
border-top: none;
background: white;
border-radius: 0px 0px 4px 4px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
max-height: 0px;
overflow: hidden;
transition-property: max-height;
transition: all 1s ease-in-out;

</style>

<div id="menu01">
<a href="" title="Alterar Dados">Meus Dados</a><hr>
<a href="" title="Alterar Senha">Alterar Senha</a><hr>
<a href="" title="Alterar Senha">Agenda</a><hr>
<a href="" title="Alterar Senha">Calendario</a><hr>
<a href="" title="Alterar Senha">Sair</a>
</div>

<button onclick="showmenu()">Menu(show/hide)</button>

<script type="text/javascript">
function showmenu()
var menu01 = document.getElementById('menu01');
menu01.style.maxHeight = '600px';

</script>


I need a solution in Javascript Vanilla. I do not use jQuery.










share|improve this question




























    0















    I have this CSS transition effect menu that is activated with a Javascript function through the click event on a button. However, I need the same button to hide the menu if it is visible.



    I tried doing this by getting the same property that is changed by the function, as follows:



    if (menu01.style.maxHeight == '0px')
    menu01.style.maxHeight = '600px';
    else
    menu01.style.maxHeight = '0px';


    However, as it may seem perfectly logical, IT DOES NOT WORK, and in addition it locks the function.
    A GLOBAL variable could solve the problem, but they say we should avoid globals because of security.



    <style type="text/css">
    #menu01
    display: block;
    position: absolute;
    top:0px;
    left: 130px;
    width: 120px;
    border-top: none;
    background: white;
    border-radius: 0px 0px 4px 4px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
    max-height: 0px;
    overflow: hidden;
    transition-property: max-height;
    transition: all 1s ease-in-out;

    </style>

    <div id="menu01">
    <a href="" title="Alterar Dados">Meus Dados</a><hr>
    <a href="" title="Alterar Senha">Alterar Senha</a><hr>
    <a href="" title="Alterar Senha">Agenda</a><hr>
    <a href="" title="Alterar Senha">Calendario</a><hr>
    <a href="" title="Alterar Senha">Sair</a>
    </div>

    <button onclick="showmenu()">Menu(show/hide)</button>

    <script type="text/javascript">
    function showmenu()
    var menu01 = document.getElementById('menu01');
    menu01.style.maxHeight = '600px';

    </script>


    I need a solution in Javascript Vanilla. I do not use jQuery.










    share|improve this question
























      0












      0








      0








      I have this CSS transition effect menu that is activated with a Javascript function through the click event on a button. However, I need the same button to hide the menu if it is visible.



      I tried doing this by getting the same property that is changed by the function, as follows:



      if (menu01.style.maxHeight == '0px')
      menu01.style.maxHeight = '600px';
      else
      menu01.style.maxHeight = '0px';


      However, as it may seem perfectly logical, IT DOES NOT WORK, and in addition it locks the function.
      A GLOBAL variable could solve the problem, but they say we should avoid globals because of security.



      <style type="text/css">
      #menu01
      display: block;
      position: absolute;
      top:0px;
      left: 130px;
      width: 120px;
      border-top: none;
      background: white;
      border-radius: 0px 0px 4px 4px;
      box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
      max-height: 0px;
      overflow: hidden;
      transition-property: max-height;
      transition: all 1s ease-in-out;

      </style>

      <div id="menu01">
      <a href="" title="Alterar Dados">Meus Dados</a><hr>
      <a href="" title="Alterar Senha">Alterar Senha</a><hr>
      <a href="" title="Alterar Senha">Agenda</a><hr>
      <a href="" title="Alterar Senha">Calendario</a><hr>
      <a href="" title="Alterar Senha">Sair</a>
      </div>

      <button onclick="showmenu()">Menu(show/hide)</button>

      <script type="text/javascript">
      function showmenu()
      var menu01 = document.getElementById('menu01');
      menu01.style.maxHeight = '600px';

      </script>


      I need a solution in Javascript Vanilla. I do not use jQuery.










      share|improve this question














      I have this CSS transition effect menu that is activated with a Javascript function through the click event on a button. However, I need the same button to hide the menu if it is visible.



      I tried doing this by getting the same property that is changed by the function, as follows:



      if (menu01.style.maxHeight == '0px')
      menu01.style.maxHeight = '600px';
      else
      menu01.style.maxHeight = '0px';


      However, as it may seem perfectly logical, IT DOES NOT WORK, and in addition it locks the function.
      A GLOBAL variable could solve the problem, but they say we should avoid globals because of security.



      <style type="text/css">
      #menu01
      display: block;
      position: absolute;
      top:0px;
      left: 130px;
      width: 120px;
      border-top: none;
      background: white;
      border-radius: 0px 0px 4px 4px;
      box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
      max-height: 0px;
      overflow: hidden;
      transition-property: max-height;
      transition: all 1s ease-in-out;

      </style>

      <div id="menu01">
      <a href="" title="Alterar Dados">Meus Dados</a><hr>
      <a href="" title="Alterar Senha">Alterar Senha</a><hr>
      <a href="" title="Alterar Senha">Agenda</a><hr>
      <a href="" title="Alterar Senha">Calendario</a><hr>
      <a href="" title="Alterar Senha">Sair</a>
      </div>

      <button onclick="showmenu()">Menu(show/hide)</button>

      <script type="text/javascript">
      function showmenu()
      var menu01 = document.getElementById('menu01');
      menu01.style.maxHeight = '600px';

      </script>


      I need a solution in Javascript Vanilla. I do not use jQuery.







      javascript html5 css3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 5:56









      Eibo - Sistemas WebEibo - Sistemas Web

      449




      449






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Its very simple, since you are adding 600px max height property, on button click add logic to check height and toggle it between 0px and 600px.



          checkout the snippet






          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>








          share|improve this answer























          • It works.Thankfully.

            – Eibo - Sistemas Web
            Mar 23 at 6:28











          • @Eibo-SistemasWeb you are welcome

            – Akhil Aravind
            Mar 23 at 6:31


















          1














          Proposing another methods based on Akhil Aravind's answer :)
          Prefer using addEventListener for future use so you can use the function for another DOM elements.



          <script type="text/javascript">
          var showMenuButton = document.getElementsByTagName('button')[0];
          var menu01 = document.getElementById('menu01');
          var elementArray = [showMenuButton, menu01];
          elementArray.forEach(function (element)
          element.addEventListener('click', function ()
          showmenu(menu01);
          )
          )
          function showmenu(menuElement)
          menuElement.style.maxHeight = menuElement.style.maxHeight == '600px' ? '0px': '600px';

          </script>


          1. delete the onclick attached to 'button' element

          2. get the get the Elements for the button and menu01

          3. add event listener for each elements. (I tried Akhil Aravind's answer code, and when you click the list item, all the elements disappear. Maybe bug)

          4. I just save the elements into an array and use for each to make it shorter(no need for writing twice)





          share|improve this answer























          • Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

            – Eibo - Sistemas Web
            Mar 23 at 8:39











          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%2f55311055%2fjavascript-get-css-height-propriety%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









          1














          Its very simple, since you are adding 600px max height property, on button click add logic to check height and toggle it between 0px and 600px.



          checkout the snippet






          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>








          share|improve this answer























          • It works.Thankfully.

            – Eibo - Sistemas Web
            Mar 23 at 6:28











          • @Eibo-SistemasWeb you are welcome

            – Akhil Aravind
            Mar 23 at 6:31















          1














          Its very simple, since you are adding 600px max height property, on button click add logic to check height and toggle it between 0px and 600px.



          checkout the snippet






          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>








          share|improve this answer























          • It works.Thankfully.

            – Eibo - Sistemas Web
            Mar 23 at 6:28











          • @Eibo-SistemasWeb you are welcome

            – Akhil Aravind
            Mar 23 at 6:31













          1












          1








          1







          Its very simple, since you are adding 600px max height property, on button click add logic to check height and toggle it between 0px and 600px.



          checkout the snippet






          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>








          share|improve this answer













          Its very simple, since you are adding 600px max height property, on button click add logic to check height and toggle it between 0px and 600px.



          checkout the snippet






          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>








          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>





          function showmenu()
          var menu01 = document.getElementById('menu01');
          menu01.style.maxHeight = menu01.style.maxHeight == '600px' ? '0px': '600px';

          #menu01
          display: block;
          position: absolute;
          top:0px;
          left: 130px;
          width: 120px;
          border-top: none;
          background: white;
          border-radius: 0px 0px 4px 4px;
          box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.1);
          max-height: 0px;
          overflow: hidden;
          transition-property: max-height;
          transition: all 1s ease-in-out;

          <div id="menu01">
          <a href="" title="Alterar Dados">Meus Dados</a><hr>
          <a href="" title="Alterar Senha">Alterar Senha</a><hr>
          <a href="" title="Alterar Senha">Agenda</a><hr>
          <a href="" title="Alterar Senha">Calendario</a><hr>
          <a href="" title="Alterar Senha">Sair</a>
          </div>

          <button onclick="showmenu()">Menu(show/hide)</button>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 6:08









          Akhil AravindAkhil Aravind

          1,714718




          1,714718












          • It works.Thankfully.

            – Eibo - Sistemas Web
            Mar 23 at 6:28











          • @Eibo-SistemasWeb you are welcome

            – Akhil Aravind
            Mar 23 at 6:31

















          • It works.Thankfully.

            – Eibo - Sistemas Web
            Mar 23 at 6:28











          • @Eibo-SistemasWeb you are welcome

            – Akhil Aravind
            Mar 23 at 6:31
















          It works.Thankfully.

          – Eibo - Sistemas Web
          Mar 23 at 6:28





          It works.Thankfully.

          – Eibo - Sistemas Web
          Mar 23 at 6:28













          @Eibo-SistemasWeb you are welcome

          – Akhil Aravind
          Mar 23 at 6:31





          @Eibo-SistemasWeb you are welcome

          – Akhil Aravind
          Mar 23 at 6:31













          1














          Proposing another methods based on Akhil Aravind's answer :)
          Prefer using addEventListener for future use so you can use the function for another DOM elements.



          <script type="text/javascript">
          var showMenuButton = document.getElementsByTagName('button')[0];
          var menu01 = document.getElementById('menu01');
          var elementArray = [showMenuButton, menu01];
          elementArray.forEach(function (element)
          element.addEventListener('click', function ()
          showmenu(menu01);
          )
          )
          function showmenu(menuElement)
          menuElement.style.maxHeight = menuElement.style.maxHeight == '600px' ? '0px': '600px';

          </script>


          1. delete the onclick attached to 'button' element

          2. get the get the Elements for the button and menu01

          3. add event listener for each elements. (I tried Akhil Aravind's answer code, and when you click the list item, all the elements disappear. Maybe bug)

          4. I just save the elements into an array and use for each to make it shorter(no need for writing twice)





          share|improve this answer























          • Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

            – Eibo - Sistemas Web
            Mar 23 at 8:39















          1














          Proposing another methods based on Akhil Aravind's answer :)
          Prefer using addEventListener for future use so you can use the function for another DOM elements.



          <script type="text/javascript">
          var showMenuButton = document.getElementsByTagName('button')[0];
          var menu01 = document.getElementById('menu01');
          var elementArray = [showMenuButton, menu01];
          elementArray.forEach(function (element)
          element.addEventListener('click', function ()
          showmenu(menu01);
          )
          )
          function showmenu(menuElement)
          menuElement.style.maxHeight = menuElement.style.maxHeight == '600px' ? '0px': '600px';

          </script>


          1. delete the onclick attached to 'button' element

          2. get the get the Elements for the button and menu01

          3. add event listener for each elements. (I tried Akhil Aravind's answer code, and when you click the list item, all the elements disappear. Maybe bug)

          4. I just save the elements into an array and use for each to make it shorter(no need for writing twice)





          share|improve this answer























          • Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

            – Eibo - Sistemas Web
            Mar 23 at 8:39













          1












          1








          1







          Proposing another methods based on Akhil Aravind's answer :)
          Prefer using addEventListener for future use so you can use the function for another DOM elements.



          <script type="text/javascript">
          var showMenuButton = document.getElementsByTagName('button')[0];
          var menu01 = document.getElementById('menu01');
          var elementArray = [showMenuButton, menu01];
          elementArray.forEach(function (element)
          element.addEventListener('click', function ()
          showmenu(menu01);
          )
          )
          function showmenu(menuElement)
          menuElement.style.maxHeight = menuElement.style.maxHeight == '600px' ? '0px': '600px';

          </script>


          1. delete the onclick attached to 'button' element

          2. get the get the Elements for the button and menu01

          3. add event listener for each elements. (I tried Akhil Aravind's answer code, and when you click the list item, all the elements disappear. Maybe bug)

          4. I just save the elements into an array and use for each to make it shorter(no need for writing twice)





          share|improve this answer













          Proposing another methods based on Akhil Aravind's answer :)
          Prefer using addEventListener for future use so you can use the function for another DOM elements.



          <script type="text/javascript">
          var showMenuButton = document.getElementsByTagName('button')[0];
          var menu01 = document.getElementById('menu01');
          var elementArray = [showMenuButton, menu01];
          elementArray.forEach(function (element)
          element.addEventListener('click', function ()
          showmenu(menu01);
          )
          )
          function showmenu(menuElement)
          menuElement.style.maxHeight = menuElement.style.maxHeight == '600px' ? '0px': '600px';

          </script>


          1. delete the onclick attached to 'button' element

          2. get the get the Elements for the button and menu01

          3. add event listener for each elements. (I tried Akhil Aravind's answer code, and when you click the list item, all the elements disappear. Maybe bug)

          4. I just save the elements into an array and use for each to make it shorter(no need for writing twice)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 6:43









          Adhi Yudana SvarajatiAdhi Yudana Svarajati

          111




          111












          • Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

            – Eibo - Sistemas Web
            Mar 23 at 8:39

















          • Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

            – Eibo - Sistemas Web
            Mar 23 at 8:39
















          Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

          – Eibo - Sistemas Web
          Mar 23 at 8:39





          Interestingly, this solution makes HTML a bit "cleaner". As for clicking on the item make the menu disappear (in Akhil Aravind's reply), it is because the link is ON and directs to the destination location, it is correct like that.

          – Eibo - Sistemas Web
          Mar 23 at 8:39

















          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%2f55311055%2fjavascript-get-css-height-propriety%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해