javascripthtmlcssdrop-down-menumobile-browser

How to display dropdown menu link in only mobile browser not desktop browsers


  <li class="megamenu-content">
    <div class="megamenu-content-wrapper clearfix">
      <ul class="col-lg-3  col-sm-3 col-md-3 ">
          <li class="cat-header">SHOW MEMBERS</li>
          <li><a class='dropdown-menu-link' href='/new-members/'>New Members</a></li>
          <li><a class='dropdown-menu-link' href='/old-members/'>Old Members</a></li>
          <li><a class='mobile-only' href='/main-page/'>Back to Page</a></li>         
       </ul>

    <script type="text/javascript">
          var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
           if(isMobile) {
            document.getElementById('mobile-only').innerHtml = "Back to page"
           }
        </script>

I am trying to show a content in dropdown menu in only mobile browser but it doesn't work. If you have any different idea, you are also welcome :) Thanks.


Solution

  • set your mobile-only class to display:none

    then use media query to specify your device's browser width

    @media screen and (max-width: mobile-width-here) {
        .mobile-only { display: block; }
    }