JavaScript functions / 2 [closed]

0

I have to create a function that will return a message box in the center of the screen with the information given by the user, however, such a message box has to be made using the div tag and Then the problem is living. Below is the code I am trying to implement.

<html>
<head>
    <script>
        function showMessage (msg) {
            msg = prompt ('Digita Mensagem' );          
            $(document).ready(function() {
                $("#div1").fadeIn(300).delay(3000).fadeOut(300);
            });         
        }       
    </script>

<style>
    #div1 {
        background-color: #90EE90;
        border-style: hidden;
        border-color: #98FB98;
        position: absolute;
        left: 700px;
        top: 400px;
    }
</style>
</head>

<body>
    <div id = "div1">

    </div>
</body>
</html>
    
asked by anonymous 17.04.2018 / 22:09

1 answer

0

Here's an example, just use the return of your prompt() and assign it to the contents of your div.

function showMessage() {
  var msg = prompt('Digita Mensagem');
  $("#div1").text(msg).fadeIn(300).delay(3000).fadeOut(300);
}

showMessage();
html,
body {
  height: 100%;
  width: 100%;
}

#div1 {  
  position:absolute;
  height:100px;
  width:200px;
  text-align: center;  
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  background-color: #90EE90;
  border-color: #98FB98;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><html><head></head><body><divid="div1">
  </div>
</body>

</html>
    
17.04.2018 / 22:29