I've the following HTML:
<a id="foo">Click Me</a>
<form action="" method="post">
<input type="submit" value="submit">
</form>
<script type="text/javascript">
$(function() {
$('#foo').click(function() {
alert('hello');
});
});
</script>
As you can see, "Click me" works fine until I click the submit button (which reloads the page).
How can I prevent this from happening so that "Click me" works as expected even after form submission?
Note: Here's what's inside my <head>
:
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" />
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
Update: I tried removing
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" />
in the head
tag, it works, however this CSS file is an essential part of Jquery Mobile.