Q:

click to show or click outside or the same button to hide

I have this code:
$(document).on('click', function(e) {
    var elem = $(e.target).closest('#click'),
        box  = $(e.target).closest('#box');

    if ( elem.length ) {
        e.preventDefault();
         showbox();
    }else if (!box.length){
         hidebox();
    }
});

So if the showbox(); line is: $('#box').toggle(); it's working perfectly. But if I use script without toggle, the button's hide stops working.
Here's full example with all details inside: http://jsfiddle.net/8SFMw/

A:

It has nothing to do with the showbox() function, its that elem.length will always return 1 and thus always be true.
try using .is(":visible"), something like...
$(document).ready(function(){
    $('#click').click(function(){
        if ($('#box').is(":visible")){
            hidebox();
        }else{
            showbox();
        }
    });
 });

