jQuery with EJS jQuery with EJS express express

jQuery with EJS


I know it is a bit late to answer this but i just want to add this comment, they have (jquery and ejs) different lifecycles one (ejs) compiles before rendering and jquery works after rendering, your problem has this kinds of cause


You need to put your jQuery <script> before the other. Otherwise $ is not yet defined.

The Browser loads every script one after the other. Say we had scripts A and B.B use something from A, then A should be before B or it wouldn't work.

TL;DR

Change this:

<script type='text/javascript'>        $(function(){            alert('inside jquery');        });     </script><script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

To this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><script type='text/javascript'>            $(function(){                alert('inside jquery');            });</script>


Put jquery script in:

$(document).ready(function(){    ...});

Now script will be run when all documents loads.