I have a problem with click function in mobile webpage. Here is my html code
<div data-role=content>
<input type="text" id="text">
<div id="ss"></div>
</div>
<script type="javascript">
$(document).ready(function() {
$("#text").keyup(function(){
$('#ss').append('<div style="background:yellow;" >Text<br/><a class="te"> alert </a></div>');
});
$(".te").click(function(){
alert("It is working");
});
});
</script>
Please help me with solving this problem.
Your element is added dynamically, use event delegation. Change your click event to:
$(document).on('click', '.te', function() {
//do stuff
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With