J. Paul J. Paul - 1 year ago 106
Javascript Question

how make popup models show automaticly

I want to make the popup run automatically, when the page opens, without clicking the button show modal , I tried to change

$(".modal_main").show();
to
$(".modal_main").false();
but I face the same problem.

<script>
$(document).ready(function(){
$(".call_modal").click(function(){
$(".modal").fadeIn();
$(".modal_main").show();
});
});
$(document).ready(function(){
$(".close").click(function(){
$(".modal").fadeOut();
$(".modal_main").fadeOut();
});
});
</script>
</head>
<body>
<button class="call_modal" style="cursor:pointer;">Show Modal</button>

</body>
</html>

Answer Source

If you want to show the modal automaticly when the page is open you should pull it from the .click statement.

Additionally don't create two .ready statements, it isn't necessary.

You can do this like that:

$(document).ready(function(){

  $(".modal_main").show();

  $(".call_modal").click(function(){
    $(".modal").fadeIn();
    $(".modal_main").show();
  });

  $(".close").click(function(){
    $(".modal").fadeOut();
    $(".modal_main").fadeOut();
  });
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download