//declare the function outside the ready() function
function YourFunctionName() {
//your code
}
$(document).ready(function(){
// Other code
});
// This is hard error to solve
// There are some cases
// 1. Your javascript code blocks have scope problem.
// 2. You may have syntax error like forget "," before Ajax request:
$.ajax({
url: requestUrl,
headers: { "token": token } // no comma error here
...
)}
// 3. In html tag `onClick` should change to id or class:
$(document).ready(function() {
$("Some id/class name").click(function(){
// your function can execute
});
});