0

I'm working on a simple project what I want to know that when I click on login button I want some thing like this enter image description here

and when i click any where except a div the div should be disappear can some one tell me how can I do something like that? sorry for my bad English i hope that i make my problem clear

<htm>
    <head> </head>
    <body>
          <div> </div>
    </body>

</html>
3
  • 2
    dinbror.dk/bpopup Commented Jul 18, 2013 at 15:11
  • 2
    jqueryui.com/dialog Commented Jul 18, 2013 at 15:11
  • @Spokey thanx that what im really looking for Commented Jul 18, 2013 at 15:24

3 Answers 3

1

You can simply do it using CSS.

Add a class to you div

<div class="someDiv"></div>

CSS

.someDiv{
    width:400px;
    height:400px;
    z-index:1000;
    background:yellow;
    position:fixed;
    top:50%;
    left:50%;
    margin-top:-150px; 
    margin-left:-150px; 
    display:none;
}

Jquery: to show

$(".someDiv").show()

on click of login button

$("#login").click(function () {
     $(".someDiv").show();
});

Demo: http://jsfiddle.net/9umYd/ and http://jsfiddle.net/9umYd/1/

Sign up to request clarification or add additional context in comments.

1 Comment

You should also make sure to set the z-index high so that it doesn't get overlapped by other elements.
0

The following code attaches a listener to the login button and once clicked will show the popup, the second part attaches a listener on the document and checks if the click was on the popup div or not

$('yourloginbutton').on('click', function(){
 $('#popup').show();
});
$(document).on('click', function(event){
 if(event.target.id != "popup"){
 $('#popup').hide();
}
});

Comments

0

Demo: http://jsfiddle.net/steven10172/u5E8z/

CSS to center perfectly in the page:

.someDiv{
    width: 500px;
    height: 500px;
    position: absolute;
    top: 0px;
    bottom: 0px;
    right: 0px;
    left: 0px;
    margin: auto;
    background: yellow;
    display: none;
    z-index: 100000;
}

JavaScript to show:

$(".someDiv").show()

HTML:

<div class="someDiv">
    Above
    <p>Paragraph</p>
    Below
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.