Try moving the bind into the deviceReady, also you need to have jquery to use $().bind
, otherwise you need to use native addEventListener
function init() {
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady(){
document.getElementById("welcomeMsg").innerHTML += "PhoneGap is ready!";
// add the clickHandler function to the click event on #bb1
document.getElementById("bb1").addEventListener('click', clickHandler);
}
function clickHandler() {
navigator.notification.alert('clicked',alertD,'Exit','ok');
}
One other thing, you should use touchstart
or touchend
for mobile applications, not the click
event, as that has a 300ms delay whilst waiting to see if it's a double click.
In this case, touchEnd
would probably be better.
document.getElementById("bb1").addEventListener('touchend', clickHandler);