Question: Hi I am using Fancy box to load some content and when a button is clicked the fancy box should close.

Here is my code:

```
function confirmation(){
        var htmlStr = '<div class="form"><form:form id="confirmBox" method="POST" action="tagging">'
        + '<label>Do you want to Map Or Tag? </label>'
        + '<br>'
        + '<br>'
        + '<br>'
        + '<input type="button" name="confMapBtn" id="confMapBtn" value="MAP" class="ui-button ui-widget ui-corner-all">'

        + '<input type="button" name="confTagBtn" id="confTagBtn" value="TAG" class="ui-button ui-widget ui-corner-all">'
        + '</form:form></div>';
    $.fancybox.open(htmlStr, {

    'width' : 950,
    'height' : 1100,
    'autoScale' : false,
    'transitionIn' : 'none',
    'transitionOut' : 'none',
    'hideOnContentClick' : false,
    'afterLoad': function(){

        $("#confMapBtn").click(function(){
            if($(this).data('clicked', true)){
                mapping();
            }
        });

        $("#confTagBtn").click(function(){
            if($(this).data('clicked', true)){
                tagging();
            }
        });
    }
    });
    }

```

**NOTE:** Whenever a button is clicked it goes to some function but before that Fancy box should be closed.

**UPDATE:** When a button is clicked from above fancy box another fancy box opens but never mind it, The current fancy box should be closed before showing the fancy box which appears after button click.

Help is appreciated, Thanks

Answer: 
Try this code: Use `$.fancybox.close();` or there will be a class called

`fancybox-close` when fancybox is opened , simply trigger a click on it. 

```
$("#confMapBtn").click(function(){
     if($(this).data('clicked', true)){
            mapping();
            $(".fancybox-close").trigger("click");
        }

}

```

**OR**

```
$("#confMapBtn").click(function(){
   if($(this).data('clicked', true)){
            mapping();
           $.fancybox.close();
   }

}

```
**Try this:**
parent.$.fancybox.close();

See [Fancybox API documentation](http://fancybox.net/api).