Functions of Javascript/2

Asked

Viewed 27 times

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 message box has to be done using the tag div And that’s where the problem is. Below is the code that I’m 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>

1 answer

0


Follow an example, just use your return prompt() and assign 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>
  <div id="div1">
  </div>
</body>

</html>

  • Running from the site, gives a good one, but when you mount the code in the IDE the message is not being displayed. It may be the order that is wrong?

  • Which IDE? Does not display text or open prompt?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.