Search code examples
javascriptjquery-mobilejqueryjquery-mobile-navbar

jQuery Mobile Alert if navbar ID is Clicked


I am trying to revise the following jQuery Mobile code to display if the navbar with the id "e" is clicked. The code below works for all of the navbar items, but I only want the alert to appear if the navbar with the id "e" is clicked. Any help revising this would be great. Thanks much!

$(document).on('pagebeforeshow', '#p_page', function(event){       
    $('div[data-role="navbar"] a').live('click', function () {

        alert("div E clicked");
});       
});

Solution

  • This should work:

    $(document).on('pagebeforeshow', '#p_page', function(event){       
        $('div[data-role="navbar"] ul li a#e').on('click', function () {
            alert("div E clicked");
        });       
    });
    

    Working example: http://jsfiddle.net/Gajotres/rnRqm/