I'm trying to use the fadeIn effect with jQuery in my python cgi code.
But for some reason it isn't working.
My python cgi code:
#!/usr/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
full_name = form.getvalue('fullname1')
address = form.getvalue('address1')
phone = form.getvalue('phone1')
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Python</title>"
print """
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$('#pad').hide().fadeIn(800).delay(3000).fadeOut(800);
</script>
"""
print "</head>"
print "<body id='two'>"
print "<h2>Full Name: %s</h2>" % (full_name)
print "<h2>Address %s</h2>" % (address)
print "<h2 id='pad'>Phone #: %s</h2>" % (phone)
print "</body>"
print "</html>"
I'm trying to fadeIn that third h2 with the id: pad.
This is what I'm using to fadeIn and fadeOut
$('#pad').hide().fadeIn(800).delay(3000).fadeOut(800);
It doesn't fade in nor fade out.
Many thanks!
Since your script is placed above #pad
, it is executing before #pad
loads. Either place the script at the end of the <body>
or wrap it in $(document).ready()
:
$(document).ready(function() {
$('#pad').hide().fadeIn(800).delay(3000).fadeOut(800);
});