I’m new to JqueryMobile. I wanted to try a simple click event on a button, but it doesn’t work (I’m using it in firefox)
The HTML is
<!DOCTYPE html>
<html dir='ltr'>
<head>
<title>Test Page</title>
<link rel="stylesheet" href="/css/style.css"/>
<script src='js/jquery.mobile.js'></script>
<script src='js/script.js'></script>
</head>
<body>
<div data-role="page" id='mypage'>
<button id='load_ajax'>Carica</button>
<br />
<div id='content'></div>
</div><!-- /content -->
</body>
</html>
and the script in script.js is
$('#mypage').delegate('#load_ajax','click',function (e) {
alert('test');
});
Even using the debugger, no alert pop up.
I suppose that the problem is that the selected elements do not exist on the page at the time your code makes the call to .delegate(). Furthermore please check that the JS files are properly loaded.
The below code which includes the code that you posted works properly:
Furthermore as mentioned in the jQuery API:
Having read the above you may consider changing your code to: