0

Looking to show/hide a div if the browser is mobile. My current code is as follow:

<script>
    if(! navigator.userAgent.match(/Android/i) && ! navigator.userAgent.match(/webOS/i) && ! navigator.userAgent.match(/iPhone/i) && ! navigator.userAgent.match(/iPod/i) &&
     ! navigator.userAgent.match(/iPad/i) &&! navigator.userAgent.match(/Blackberry/i) )
    {
     $('#mobile').hide();
    } else {

        $('#mobile').show();
        alert('tablet detected');
        //turns on mobile DIV
    }
</script>

I receive the alert when viewing mobile but do not see my #mobile div. Any suggestions greatly appreciated.

JasonMArcher
  • 12,386
  • 20
  • 54
  • 51
yamahaha
  • 11
  • 1
  • what's the code for your div? are you sure you're defining 'mobile' as it's id and not as class? – FabioG Feb 11 '14 at 10:51
  • This answer might help: http://stackoverflow.com/a/11381730/1838483 – AfromanJ Feb 11 '14 at 11:02
  • it might be showing but you're just not seeing it, since you're using absolute positioning, try giving it specific position with `top: 10px; left: 10px`for example. just to check. – FabioG Feb 11 '14 at 11:13
  • Ah its because i'm trying to execute the script without the document being ready first. I moved the script to the bottom of my doc and sure enough my div appeared. Thank you! – yamahaha Feb 11 '14 at 11:15

0 Answers0