0

I want to show popup div by clicking on button and then i want to hide same div by clicking on the same button. I want to hide div even when user clicks outside the div.

<div id="div_fieldWorkers" class="form_size"></div>

this is my div.. it contains a form to be filled by the user.

<input
    type="button"
    value="Add Field Worker"
    id="btnFieldWorkers"
    class="btn btn-primary" />

This is the button. help me do this using jquery

Manu
  • 418
  • 3
  • 8
  • 20

2 Answers2

0
<a href="javascript:hideshow(document.getElementById('adiv'))">Click here</a>

<script type="text/javascript">
function hideshow(which){
if (!document.getElementById)
return
if (which.style.display=="block")
which.style.display="none"
else
which.style.display="block"
}
</script>

<div id="adiv" style="font:24px bold; display: block">Now you see me</div>
0

Check if this code works for you:

Style:

    #messagewrapper
    {
        position: fixed;

        bottom: 10px;
        right: 10px;
        z-index: 1000;
        margin: 5px auto;
        width: auto;
    }

    #messagewrapper .messagebox
    {
        padding: 6px 5px 5px 6px;
        box-shadow: 5px 5px 10px #000;
    }

HTML Code:

<div id="messagewrapper" style="display: none">     
</div>

Java Script:

function displayNotification(message) {
    $("#messagewrapper").html('<div class="messagebox"></div>');
    $("#messagewrapper .messagebox").text(message);
    displayMessages();
}

function displayMessages() {
    if ($("#messagewrapper").children().length > 0) {
        $("#messagewrapper").show();
        $(document).click(function() {
            clearMessages();
        });
    }
    else {
        $("#messagewrapper").hide();
    }
}

function clearMessages() {
    $("#messagewrapper").fadeOut(500, function() {
        $("#messagewrapper").empty();
    });
}

Use displayNotification('Message'); to show div and clearMessages() to hide this div.

Vishal Vaishya
  • 596
  • 3
  • 15
  • No I guess. I think either toggle works for targeted element or we can toggle between two elements. – Vishal Vaishya Sep 30 '13 at 10:47
  • Please answer this question http://stackoverflow.com/questions/19092433/close-popup-div-when-clicked-outside – Manu Sep 30 '13 at 10:56