Search code examples
jquerylistviewmobileclick

jquery mobile click() on listview


I have a problem with the listview in jquery mobile. I want to load some data from a server using JSON and fill thy listview with the items. That works fine. But when I am trying to react on a click on a new loaded item I do net get the event! I think I have to refresh the view somehow, bit do not know how.

I made a little sketch on http://jsfiddle.net/VqULm/227/

when u hit the click me button the click event on a item isn't tracked anymore. How do i get the "Wokrs" alert on the new items?

Thank u very much for reading!


Solution

  • Try

        $('#listview').on('click', 'li', function() {
            alert("Works"); // id of clicked li by directly accessing DOMElement property
        });
    

    with jQuery > 1.7

    DEMO

    OR

    $('#listview li').live('click', function() {
        alert("Works"); // id of clicked li by directly accessing DOMElement property
    });
    

    with your jQuery version 1.6.4.

    DEMO

    why you need this

    Because. you're adding li within listview after page reload, so any event for those lis should live (for jQuery version you used) or delegate (jQuery > 1.7).