Mallikarjun Mallikarjun - 1 year ago 902
CSS Question

How do I display image in Alert/confirm box in Javascript?

How to display image in alert box or confirm box? I have been trying with below code but getting image url in the alert box. Please anybody help me to get solve or please give any other suggestions if it does not possible.

var image = document.getElementById("myImage").src="hackanm.gif";
alert("OnLoad image"+image );

Answer Source

Alert boxes in JavaScript can only display pure text. You could use a JavaScript library like jQuery to display a modal instead?

This might be useful:

You can do it like this:

<!doctype html>

<html lang="en">
  <meta charset="utf-8" />
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="" />
  <script src=""></script>
  <script src=""></script>
  body {
    font-family: "Trebuchet MS", "Helvetica", "Arial",  "Verdana", "sans-serif";
    font-size: 62.5%;

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

<div id="dialog" title="Basic dialog">
  <img src="" alt="Placeholder Image" />


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download