close and open popup with one button in jquery mobile

jquery, jquery-mobile, popup

Solution

Check if the popup is whether open, accordingly, `.popup("open")` or `.popup("close")`.

$(document).on('click', '#zozo', function () {
    if ($(".ui-popup-active").length > 0) {
        $('#zozo-list').popup('close');
    } else {
        $('#zozo-list').popup('open');
    }
});

Demo

Problem

I am trying to make a jquery mobile popup button which should perform two functions: on first click: open popup; on second click: close that popup; I have already made: - a dismissible button which programmatically opens a popup; Here is the code that I'm using: http://jsfiddle.net/MKHnS/ JS: ``` $(document).on('click', '#zozo', function () { $('#zozo-list').popup(); $('#zozo-list').popup('open'); }) ``` Now I need to: - make second function : next click on same button should close the popup; Any suggestions and help would be appreciated...

Original source