I have an issue with my code, I'm trying to create a function to hide and show a div and it's working, but it dosnt work at first, It works only on the second click, so i have to click the link first to get it to start working properly, how can i fix it so that it works on first click?
more info:
im trying to have a div appear and then disapear usin the display and hide functions, the catch is i also want it to disapper when im outside of the div, if its visible, its all working but the problem is when i first load the page thn click the link to display the div, it dosnt appear, only when i click it a second time does it appear. this is the problem i want to fix
this is my code:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    
    <script src="js/jquery.foggy.min.js"></script>    
    <style>
        body {
            background: black;
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: center;
            background-size: 100%;
            color: white;
            font-family: 'Segoe UI';
            font-size: 24px;
        }
        .box 
        {
            width: 100%;
            margin: auto;
            top: 0px;
            left: 20%;
            right: 0px;
            bottom: 0px;
            background-color: white;
            opacity: 0.4;
            position: fixed;
            overflow-y: scroll;
            overflow-x: scroll;
        }
    </style>
  </head>
  <body>
    <script lang="en" type="text/javascript">
        $(document).ready(function () {
        });
        $(document).mouseup(function (e) {
            var container = $("#boxwrapper");
            if (!container.is(e.target) && container.has(e.target).length === 0) {
                if (container.is(':visible'))
                    Hide();
            }
        });
        function Display() {
            $("#boxwrapper").show();
            $("#boxwrapper").addClass("box");
            $("#main").foggy();
        }
        function Hide() {
            $("#boxwrapper").hide();
            $("#main").foggy(false);
        }
    </script>
        <div id="main">
               <a href="#" onclick="Display()">Display Div</a>
        </div>
        <div id="boxwrapper">
        </div>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  </body>
</html>
 
     
     
     
    