This is stumping me and I can't figure it out. Help is needed, please. I have custom messages for both mail processing success and failure. I can test-display any of the messages within the document ready script, but it wouldn't work in the javascript script from the body. Below is the relevant parts of the code.
<?php
session_start();
if (mail($to, $subject, $message, $headers)) {
?>
<script language="javascript">
//This works
alert("Email sent);
//Not working
$("#main").css('display', 'none');
$("#emailSuccess").css('display', 'block');
$("#emailError").css('display', 'none');
</script>
<?php
} else {
?>
<script language="javascript">
//This works
alert("Email failed);
//Not working
$("#main").css('display', 'none');
$("#emailGood").css('display', 'none');
$("#emailBad").css('display', 'block');
</script>
<?php
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
(etc)
</head>
<body class="w3-content" style="max-width:1600px">
<div id="page-wrap">
<!—Success Msg
<div id="emailGood" style="display:none"> <h3>We received your email.</h3>
</div>
<!—Error Msg
<div id="emailBad" style="display:none"> <h3>We received your email.</h3>
</div>
<div id="main">
<form action="mymail.php" method="post" id="change-form">
…. (form elements)
</form>
<div>
</div>
<script>
$(document).ready(function() {
$("#main").css('display', 'none');
$("#emailGood ").css('display', 'block');
$("#emailBad ").css('display', 'none');
})
</script>
</body>
</html>