5

I'm trying to make an sweet alert with the html option:

swal({  
   title: "HTML <small>Title</small>!",  
   text: "A custom <span style="color:#F8BB86">html<span> message.",   
   html: true 
});

But instead of that text put a button, I have tried this one:

var boton = "button";
swal({   
    title: "HTML <small>Title</small>!",  
    text: "<input type=" + boton + ">",  
    html: true 
});

but it doesn't work! (I want to make something like a menu with options(the buttons)) Does anybody know how to do something like that? Thanks!

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
  • Can you share the fiddle demo? – Krish Jan 28 '16 at 10:19
  • do u want text instead of button in http://jsfiddle.net/BDhara/xe096w10/160/ – Dhara Jan 28 '16 at 10:26
  • Is sweetalert a plugin? – ickyrr Jan 28 '16 at 10:31
  • mmm...I want soemthing more like a menu with (button1) Option1 (button2) Option2 (button3) Option3 The thing is that in the first code the second quotation marks work fine (in the style) But when i try my code it shows a "html"file but not the button. I mean if you put a

    appears,an
    and other stuffs but the input doesn't work a piece of code that may help: if(keyMap & 4){ here the sweet alert }

    – Miren Igone Bruna Dominguez Jan 28 '16 at 10:34

2 Answers2

8

You can use button tag instead of input.

Like this:

var boton = "button";
swal({   
    title: "HTML <small>Title</small>!",  
    text: '<button type="' + boton + '">Button</button>',
    html: true 
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
1

The reason why the button is not shown in the alert is because the css rules regarding inputs are by default set to hide them.

You can override the default css behavior of sweetalets by using:

.sweet-alert input {
  display: initial !important;
}

What I would suggest is give a class to your input, and add explicit rules in your CSS so it doesn't interfere with any other input tags used by the plugin.

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125