My jQuery function is not firing when called with an event.
If I put my function outside the event, though, everything works perfectly and there are no errors.
But, if I try to trigger it with an event, specifically submit or click, nothing happens and I don't get any errors.
I'm using Cordova, but when testing this on a test server on my computer, the same issues happen.
My Cordova Doc
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<!-- Load jQuery-->
<script src="js/jquery.min.js" type="text/javascript"></script>
<!-- Load My JS Plugins -->
<script src="js/login.jQuery.js" type="text/javascript"></script>
<!-- jQuery Variables and other code used across the plugins-->
<script type="text/javascript">
$(document).ready(function()
{
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position)
{
//Trigger My Functions
$("#login").submit(function()
{
$(this).login();
});
}
function onError(error)
{
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
}
}
});
</script>
</head>
<body>
<div id="deviceready">
<div class="loginstuff">
<form id="login">
<h2>Login to your Account</h2>
<label>Username</label>
<input id="username"placeholder="Username" autocapitalize="off" autocorrect="off" type='text'>
<br>
<label>Password</label>
<input id="password" placeholder="********" type='password'>
<br>
<input type="submit" value="Login">
</form>
</div>
</div>
</body>
</html>
NOTE - I know this plugin is simple, but I'm just using it for testing. Once I know it can be fired, I'll switch it back
(function ($) {
$.fn.extend({
login: function()
{
alert("yes");
}
});
})(jQuery);
EDIT
So I tested the function in a jsFiddle and everything worked perfectly. Basically, now I know my function works as is, but that the event is not firing. Wanted to let everyone know that.