0

A jQuery CSS button transition animation works perfectly in CodePen, however when identical code is used in a Node.js server, the transition does not work.

No errors are thrown by the browser console.

Link to my CodePen fork:

CodePen Link

This is the identical code being run on the server. Server HTML File:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet/less" type="text/css" 
href="/css/login_styles.less" />
<script 
src="https://cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js" 
></script> <script 
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/
jquery.min.js"></script>
<script>
$("#login-button").click(function(event){
event.preventDefault();

$('form').fadeOut(500);
$('.wrapper').addClass('form-success');
});
</script>
</head>
<body>
<div class="wrapper">
     <div class="container">
           <h1>Welcome</h1>
             <form class="form">
                    <input type="text" placeholder="Username">
                       <input type="password" placeholder="Password">
                          <button type="submit" id="login- 
                                button">Login</button>
                        </form>
</div>

<ul class="bg-bubbles">
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>
</div>
</body>

</html>

Server CSS Less file: Identically copy pasted from CodePen Link

When run from the Node.js server, all works fine except the transition when the login button is clicked.

Can anyopne spot why or is this a bug within jQuery?

R.Snow
  • 21
  • 1
  • 5
  • 1
    is there an error on console ? – Ismail Farooq Nov 07 '18 at 05:28
  • 1
    The body tag seems to be missing, also see https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element – Teemu Nov 07 '18 at 05:32
  • No error in console. Adding body tag makes no difference. It's almost as if the browser is simply ignoring the instruction for the button click? – R.Snow Nov 07 '18 at 05:40
  • As Teemu suggested, try loading the scripts at the end of the file (that is, keep libraries in the head, and move your own script to the end of the body. – Battlesquid Nov 07 '18 at 05:50

2 Answers2

0

try button type="button" ... worked for me

ijhar
  • 11
  • 4
  • it needs to stay as submit as it will be further integrated with form post submit actions. Thanks for you help however. I have found the issue. the script tag needs to be placed AFTER the button. Then everything works perfect – R.Snow Nov 07 '18 at 05:44
0

Issue solved. Script tag containing the jQuery needs to be placed after the form tag. Then everything works perfect.

R.Snow
  • 21
  • 1
  • 5