You could use jquery ui dialog, or, if you want to get more ...fancy, you could use fancybox:

$(document).ready(function() {
    $("a#inline").fancybox({
		'hideOnContentClick': true
	});
  
  
});
.btn{
  border: 1px solid #006; 
  color:#01ACEE; 
  font: bold 16px Tahoma; 
  border-radius:7px; 
  padding:4px;
  
  }
<link rel="stylesheet" href="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.mousewheel-3.0.4.pack.js"></script>

<a id="inline" class="btn" href="#data">My Button</a>

<div style="display:none">
    <div id="data">
    <img alt="" src="http://farm9.staticflickr.com/8366/8483546751_86494ae914_m.jpg"><br>
        <h3>My Cool Title</h3>
        <p>Put your cool item descrtiption here</p>
   </div>
</div>

Answer from Wesley Smith on Stack Overflow
Top answer
1 of 2
1

You could use jquery ui dialog, or, if you want to get more ...fancy, you could use fancybox:

$(document).ready(function() {
    $("a#inline").fancybox({
		'hideOnContentClick': true
	});
  
  
});
.btn{
  border: 1px solid #006; 
  color:#01ACEE; 
  font: bold 16px Tahoma; 
  border-radius:7px; 
  padding:4px;
  
  }
<link rel="stylesheet" href="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.mousewheel-3.0.4.pack.js"></script>

<a id="inline" class="btn" href="#data">My Button</a>

<div style="display:none">
    <div id="data">
    <img alt="" src="http://farm9.staticflickr.com/8366/8483546751_86494ae914_m.jpg"><br>
        <h3>My Cool Title</h3>
        <p>Put your cool item descrtiption here</p>
   </div>
</div>

2 of 2
1

You can try jquery ui dialog like,

HTML

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

SCRIPT

$(function() {
    $( "#dialog" ).dialog();
});

Also you can try bootstrap modal

🌐
W3Schools
w3schools.com › howto › howto_js_popup.asp
How To Create Popups
Learn how to create popups with CSS and JavaScript. Click me to toggle the popup! A Simple Popup! ... <div class="popup" onclick="myFunction()">Click me!
Top answer
1 of 3
11

You basically have three ways:

  1. By hand: make the popup div floating and position it absolutely, then set top to 100% (this will make it look like a popup menu. Make sure the parent element has relative positioning.

    HTML:

    <div class="input-group" style="position: relative;">
      <div class="SearchCities">
        ...
      </div>
    </div>
    

    CSS:

    .SearchCities {
      float: right;
      position: absolute;
      top: 100%;
    }
    

    JS: No change required

  2. Use jQueryUI's dialog plugin: as pointed out in nrsharma's answer you can use a jQuery plugin to make it look like a popup dialog.

    $('.SearchCities').dialog({ autoOpen: false }); // Initialize dialog plugin
    $('.SearchCities').dialog("open"); // Open popup
    

    API Reference: http://api.jqueryui.com/dialog/

    Examples: http://jqueryui.com/dialog/

    Plugin download: http://jqueryui.com/download/

  3. Use Bootstrap's dropdown component: it seems from your code that you're using bootstrap. You can easily use bootstrap dropdowns or modals.

    Bootstrap modals are popup dialogs just like jQueryUI's dialog plugin, but they look better and they're much more customizable. Have a look there for an example: http://getbootstrap.com/javascript/#modals

    Bootstrap dropdowns are simple dropdown menus, but with a bit of hacking you can put anything inside them.

    All you need is a bit of HTML (no JavaScript):

    <div class="input-group dropdown">
      <button type="button" class="btn btn-default dropdown-toggle"
        data-toggle="dropdown" id="dropdownBtn" role="button">...</button>
      <div class="dropdown-menu SearchCities" role="menu">
        ...
      </div>
    </div>
    

    To make this work you also need to include Bootstrap js plugins (bootstrap.js/bootstrap.min.js).

    Reference: http://getbootstrap.com/javascript/#dropdowns

2 of 3
5

Here you can do this easily

HTML

<div class="dialogbox"> This is Dialogue box</div>
<a id="click">click here</a>

CSS

.dialogbox{width:100px; height:100px; background:grey;display:none}

JQUERY

<script src="latest jquery library"></script>

    <script>

    $(document).ready(function(){
    $("#click").click(function(){

    $(".dialogbox").toggle();

    });

    });
   </script>
Top answer
1 of 4
9

Here is a fiddle that actually does what you want - http://jsfiddle.net/WGPhG/6/

JS

function popUp(){
    var popup = document.createElement('div');
    popup.className = 'popup';
    popup.id = 'test';
    var cancel = document.createElement('div');
    cancel.className = 'cancel';
    cancel.innerHTML = 'close';
    cancel.onclick = function (e) { popup.parentNode.removeChild(popup) };
    var message = document.createElement('span');
    message.innerHTML = "This is a test message";
    popup.appendChild(message);                                    
    popup.appendChild(cancel);
    document.body.appendChild(popup);
}

NOTES

To set the class on an element you use element.className instead of element.class. For the onclick event handler on the cancel element, it is better to directly assign the onclick handler with an anonymous function that does what you need as in my example above.


EDIT (More Efficient Way)

This is actually a much better of getting the results that you want because there is no overhead involved with recreating the elements every time the popup is shown. Fiddle - http://jsfiddle.net/WGPhG/7/

CSS

.popup
{
    position:absolute;
    top:0px;
    left:0px;
    margin:100px auto;
    width:200px;
    height:150px;
    font-family:verdana;
    font-size:13px;
    padding:10px;
    background-color:rgb(240,240,240);
    border:2px solid grey;
    z-index:100000000000000000;
    display:none
}

.cancel
{
    display:relative;
    cursor:pointer;
    margin:0;
    float:right;
    height:10px;
    width:14px;
    padding:0 0 5px 0;
    background-color:red;
    text-align:center;
    font-weight:bold;
    font-size:11px;
    color:white;
    border-radius:3px;
    z-index:100000000000000000;
}

HTML

<button onClick="openPopup();">click here</button>
<div id="test" class="popup">
    This is a test message
    <div class="cancel" onclick="closePopup();"></div>
</div>

JS

function openPopup() {
    document.getElementById('test').style.display = 'block';
}

function closePopup() {
    document.getElementById('test').style.display = 'none';
}
2 of 4
1

Try this update on JSFiddle

Changed :

  1. Center page (fixed).
  2. effect (fadein and fadeout)

HTML

<button onClick="openPopup();">click here</button>
<div id="test" class="popup" style="display:none;">
    This is a test message
    <div class="cancel" onclick="closePopup();"></div>
</div>

CSS

.popup {
    position:fixed;
    top:0px;
    left:0px;
    bottom:0px;
    right:0px;  
    margin:auto;
    width:200px;
    height:150px;
    font-family:verdana;
    font-size:13px;
    padding:10px;
    background-color:rgb(240,240,240);
    border:2px solid grey;
    z-index:100000000000000000;
}

.cancel {
    display:relative;
    cursor:pointer;
    margin:0;
    float:right;
    height:10px;
    width:14px;
    padding:0 0 5px 0;
    background-color:red;
    text-align:center;
    font-weight:bold;
    font-size:11px;
    color:white;
    border-radius:3px;
    z-index:100000000000000000;
}

.cancel:hover {
    background:rgb(255,50,50);
}

JS

function openPopup() {
    //document.getElementById('test').style.display = 'block';
   $('#test').fadeIn(1000);
}

function closePopup() {
    //document.getElementById('test').style.display = 'none';
    $('#test').fadeOut(500);
}
🌐
CodePen
codepen.io › marine-fraysse › pen › eYmBEvQ
Pop-up on Button Click
<button class="button" href="#" onclick="show('popup')">Button</button> <!-- This is what will be included inside the popup --> <div class="popup" id="popup"> <p>This is a popup!</p> <p>Overlay uses <b>:before</b> and <b>:after</b> ...
🌐
Cortland University
web.cortland.edu › flteach › mm-course › glossPopupDiv.html
Making a popup window using a DIV
A DIV is a very powerful HTML object that can be used for many purposes. Think of a DIV as a rectangle that can appear on a web page, be positioned where you wish, and hover over other content on the page. A DIV can be referred to by it's name or ID. It can have a particular location, size, ...
🌐
CodeInDotNet
codeindotnet.com › show-javascript-popup-in-page-using-html-div-element-css
Show JavaScript Popup in a webpage using Div Elements & CSS - CodeInDotNet
April 2, 2024 - <html> <head> <script> ... element var close = document.getElementById('btnpopclose'); // add javascript onclick event and function to display the popup document.getElementById("showpopup").addEventListener("click", function ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-open-a-popup-on-click-using-javascript
How to Open a Popup on Click using JavaScript ? - GeeksforGeeks
August 5, 2025 - <!DOCTYPE html> <html> <head> <title>Using display property</title> <style> #popupDialog { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 20px; background-color: #fff; border: 1px solid #ccc; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); z-index: 1000; } #overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 999; } h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3>Using display property</h3> <button onclick="popupFn()"> Open Popup </button> <div id="overla
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 59544307 › how-to-make-pop-up-div-hide-show-on-click
javascript - How to make pop-up div hide/show on click - Stack Overflow
// When the user clicks on div, open the popup function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); $(".popup").toggleClass('active'); }
Top answer
1 of 3
139

DEMO

In the content area you can provide whatever you want to display in it — using the following code from https://gist.github.com/westonwatson/3914027 that I have copied in here:

.black_overlay {
  display: none;
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  background-color: black;
  z-index: 1001;
  -moz-opacity: 0.8;
  opacity: .80;
  filter: alpha(opacity=80);
}
.white_content {
  display: none;
  position: absolute;
  top: 25%;
  left: 25%;
  width: 50%;
  height: 50%;
  padding: 16px;
  border: 16px solid orange;
  background-color: white;
  z-index: 1002;
  overflow: auto;
}
<html>

<head>
  <title>LIGHTBOX EXAMPLE</title>
</head>

<body>
  <p>This is the main content. To display a lightbox click <a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">here</a>
  </p>
  <div id="light" class="white_content">This is the lightbox content. <a href="javascript:void(0)" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a>
  </div>
  <div id="fade" class="black_overlay"></div>
</body>

</html>

2 of 3
15

You can simply use jQuery UI Dialog

Example:

$(function() {
  $("#dialog").dialog();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
</head>

<body>
  <div id="dialog" title="Basic dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
  </div>
</body>
</html>

Top answer
1 of 1
1

Changes

div#main has been changed to dialog#main. <dialog> is a built-in HTML tag and is normally hidden unless it has the open attribute or has been opened by one of it's methods either .showModal() or .show(). .showModal() is what you'd be interested in because there's a special CSS property that only applies to fullscreen backgrounds or a dialog's backdrop -- it's appropriately called ::backdrop (see CSS of example).

Added 2 buttons one to close the <dialog> and another to open it.

Added a flag which is true to start out at then once the <dialog> opens that button generating function starts and then that flag is set to false. I had to stop it because I'm not sure if you wanted it to keep making buttons every time the <dialog> opens or not. Anyways, the flag is easily removed or you could adjust the conditions in which the flag is set to.

const modal = document.querySelector(".smallFrame");
const show = document.querySelector('.show');
const hide = document.querySelector('.hide');

let flag = true;
show.onclick = popUp;
hide.onclick = e => modal.close();

function popUp(e) {
  modal.showModal();
 
  if (!flag) {
    return;
  }
  let tempCounterBtn = 0;
  for (let i = 0; i < 2; i++) {
    let newDiv = document.createElement("div");
    newDiv.id = "div-" + (i + 1);
    modal.appendChild(newDiv);
    for (let x = 0; x < 6; x++) {
      let btn = document.createElement("button");
      btn.id = "button-" + (tempCounterBtn + 1);
      tempCounterBtn++;
      newDiv.appendChild(btn);
    }
  }
  flag = false;
}
html {
  font: 300 2ch/1.25 'Segoe UI'
}

body {
  display: flex;
  justify-content: center;
  margin: 1.2em;
}

button {
  background: rgba(0, 0, 0, 0);
  color: #a5afaa;
  border: 1px solid white;
  border-radius: .6em;
  padding: 3em;
}

button:hover {
  border-color: #fff8cc;
  box-shadow: 0em 0em 1em 0em yellow;
}

#main {
  border: solid 2px #939388;
  border-radius: 10px;
  background-color: #0f0f3de8;
  box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
}

#main::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.inner {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
}

.smallFrame {
  border: solid 2px #939388;
  border-radius: 10px;
  background-color: #0f0f3de8;
  box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
  width: 400px;
  height: 250px;
}

.hide {
  padding: 0.5em;
  float: right;
}

.show:hover,
.hide:hover {
  border-color: #fff8cc;
  box-shadow: 0em 0em 1em 0em lime;
  cursor: pointer;
}
<div id="main">
  <div id="inner-15" class="inner"></div>
</div>
<button class='show'>Show</button>

<dialog class="smallFrame">
  <button class='hide'>Close</button>
</dialog>

Top answer
1 of 3
1

You can use jQuery UI like this:

JS:

$(function(){
        $('.profile1').on("click", function(e){
            e.preventDefault()
            $('.picture').dialog({
            width: 600,
            height: 'auto',
            modal:true,
            title: 'Picture',
            overlay: { backgroundColor: "#000", opacity: 0.9 }
            })
        })
       })

HTML:

<div class="box"> 
 <div class="box"> <div class="profile1"> 
  <p class="name">NAME</p>
 </div>
 <div class="picture">Photo Here...</div>

</div>

CSS for ".picture":

.picture{
    display:none;
    width:30%;
    height:30%;
}

And don't forget to include jQuery UI in addition to jQuery and the jQuery UI CSS:

jQuery: <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

jQuery UI:<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

CSS: https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-lightness/jquery-ui.min.css(you should download this CSS, not link to CDN)

JSFiddle: https://jsfiddle.net/91k8xa22/

2 of 3
0

Tell me if I can improve it :)

https://jsfiddle.net/www139/x6q7Ls5g/

window.addEventListener('load', function() {
  var profileBox = document.getElementsByClassName('profile1')[0];
  var picture = document.getElementsByClassName('picture')[0];
  profileBox.addEventListener('click', function() {
    document.getElementById('popupbox').style.display = 'block';
    picture.innerHTML = '<img src="http://freetopwallpaper.com/wp-content/uploads/2013/09/beautiful-background-wallpaper-hd-3.jpg">';
  });
});
.box {
  left: 19.5%;
  top: 11.5%;
  height: 85%;
  right: 2.2%;
  background-color: #F2F2F2;
  border-radius: 5px;
  position: absolute;
  border: 1px soid F2F2F2(0, 0, 0, 0.3);
  z-index: -1;
  overflow: auto;
}
.profile1 {
  margin-left: 1.7%;
  margin-top: 6%;
  height: 40%;
  width: 18%;
  background-color: #0D7BFF;
  position: absolute;
  z-index: -1;
  border-radius: 2px;
}
#popupbox {
  position: fixed;
  width: 50vw;
  height: 50vh;
  background-color: #eee;
  display: none;
}
<div class="box">
  <div class="profile1">
    <div class="picture"></div>
    <p class="name">NAME</p>
  </div>
</div>
<!--popup box-->
<div id="popupbox">This is the popup box</div>
<!--end popup box-->

🌐
WowOptin
wowoptin.com › show-popup-on-button-click
How to Show a Popup on Button Click [2 Easy Methods]
March 17, 2025 - There are two main ways to show a popup on button click: 1. Using JavaScript: JavaScript allows you to manually code an on-click popup that appears when a user clicks a button.
🌐
CodeSpeedy
codespeedy.com › home › display div element content in a new popup window – javascript
Display div element content in a new popup window - JavaScript
October 8, 2018 - On clicking the button, we are ... }); In the above JavaScript code, we apply the click event listener to the button so that clicking the button open our new popup window....
🌐
Stack Overflow
stackoverflow.com › questions › 74317135 › create-popup-for-existing-button
javascript - Create Popup for existing button - Stack Overflow
You could try wrapping the button in a div with an onclick for the div, in which you preventDefault(), then show your popup, and use JS or jQuery to "click" the button you can't modify.
Top answer
1 of 2
2

Not sure what you want exactly as your output, but the correct way of doing the code is as below:

<h2>Popup</h2>

<div class="popup" onclick="myFunction('Harry Potter','Wizard')">
  <button> Try it </button>
  <span class="popuptext" id="myPopup">Ankit </span>
</div>

<p id="demo"></p>

<script>
// When the user clicks on div, open the popup
document.getElementById("myPopup").innerHTML= "Welcome " + name + ", the " + job + ".";
function myFunction(name,job) {

    var popup =document.getElementById("myPopup");
    popup.innerHTML = "Welcome " + name + ", the " + job + ".";
    popup.classList.toggle("show"); 
}
</script>

With respect to this code,

On clicking the "Try it" button, you will get a pop-up as "Welcome Harry Potter, the Wizard. ". The reason being you passed the values "Harry Potter" as name and "Wizard" as job onclick="myFunction('Harry Potter','Wizard')"

Now, in the function, you declared a variable named popup which stores the value from id "myPopup", which is in this case is "Ankit" right now

In the next line, we are changing the value to be "Welcome " + name + ", the " + job + ".", turning the line to be "Welcome Harry Potter, the Wizard". The value "Ankit" is lost.

popup.classList.toggle("show"); simply creates the pop-up.

If in case you wish to have "Ankit" as well in the pop-up, you may wish to try this snippet:

<div class="popup" onclick="myFunction('Harry Potter','Wizard')">
  <button> Try it </button>
  <span class="popuptext" id="myPopup"> Hi, I am Ankit. </span>
</div>

<p id="demo"></p>

<script>
// When the user clicks on div, open the popup
document.getElementById("myPopup").innerHTML= "Welcome " + name + ", the " + job + ".";
function myFunction(name,job) {

    var popup =document.getElementById("myPopup");
    popup.innerHTML = popup.innerHTML + " Welcome " + name + ", the " + job + ".";
    popup.classList.toggle("show"); 
}
</script> 

The popup will now show you as "Hi, I am Ankit. Welcome Harry Potter, the Wizard".

Hope this helps in some way :)

2 of 2
1

Try this code, i tried it myself and it worked

<div class="popup" onclick="myFunction('some text')">Click me to toggle the popup!
<span class="popuptext" id="myPopup"></span>
</div>
<script>
// When the user clicks on div, open the popup
function myFunction(value) {
    var popup = document.getElementById("myPopup");
    popup.innerText = value;
    popup.classList.toggle("show");
}
</script>