jQuery HTML Element How to - Display an image on when the submit button is clicked








Question

We would like to know how to display an image on when the submit button is clicked.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<style type='text/css'>
#load {<!--  w  w  w .java2s.c  o m-->
  position: fixed;
  background: #EEE;
  opacity: 0.5;
  left: 22px;
  top: 0px;
  width: 100%;
  height: 100%;
  display: none;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
     $("form").submit(function(){
        $("#load").show();
     });
});//]]>  
</script>
</head>
<body>
  <form action="" method="post">
       <input type="Submit" value="submit">
  </form>
  <div id="load">
    <img src="http://www.java2s.com/style/download.png" />
  </div>
</body>
</html>

The code above is rendered as follows: