Before you say that is duplicate from other topics, I've seen that topics, such as:
jQuery: trigger click() doesn't work?
jQuery .on Click second time not working
Jquery Onclick not happening second time
one Jquery is not working on the second click
And none of that help me. My code is very simple:
index.php
/* in body tag */
<input type="button" id="page-add" value="Add" data-role="none"/>
/* after body tag */
$(function(){
$("#page-add").click(function(e){
window.location.href = 'add.php';
});
});
add.php
/* in body tag */
<div class="ui-btn-left"><a href="index.php"><img src="images/logo.png"/></a></div>
The button "page-add" onClick event
works for the first time, when I click the <a href>
and it backs to the index.php, if I click again on the same button it doesn't work no more. I've to refresh the page so it can work again.
I've tried to add before the window.location.href
the code e.preventDefault()
but didn't work either. I don't receive any errors on console.
What am I doing wrong?
Edit: Solved.
$(document).on('pagebeforeshow', '#main', function(){
$('#page-add').bind('click',function(){
$.mobile.changePage('add.php');
});
});