Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery mobile click event not working

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.

like image 624
Guwanch Avatar asked May 28 '13 14:05

Guwanch


1 Answers

Your element is added dynamically, use event delegation. Change your click event to:

$(document).on('click', '.te', function() {
    //do stuff
});
like image 174
tymeJV Avatar answered Nov 17 '22 22:11

tymeJV