I would like you to help me give css to the and alert()
javascript , so that my messages are somewhat elegant, I do not want to opt for a modal only for confirmations, so if someone knew how I do it, I would appreciate it.confirm()
$("#confirm").click(function(){
var bool=confirm("Seguro de eliminar el dato?");
if(bool){
alert("se elimino correctamente");
}else{
alert("cancelo la solicitud");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="confirm">confirmar eliminacion</button>
Unfortunately it is not possible .
The
alert
,prompt
andconfirm
are created by the browser and their visual styles depend entirely on the browser.Browser Example:
Chrome
Edge
firefox
internet explorer
They are not part of the DOM and therefore cannot be styled by CSS or JavaScript.
The only thing you can do is precisely what you mentioned you didn't want: Use a modal from a library of your choice or do the code yourself .
It is not possible to apply css rules to edit the
alert()
orconfirm()
.I recommend you Bootbox.js , although they are modals, they are very easy to use and they also have the confirm function.
There is a very good library, AlertifyJS .
It's responsive and uses jQuery, so it's supported by almost all old browsers. You can make a nice and functional commit with just these lines of code.
I recommend you to use sweet alert, check the link: http://t4t5.github.io/sweetalert/
}
Expanding on the answer, download the library and call your function. Note: in the link there are more examples for its use.
You can use SweetAlert is very friendly
Link : Website
You can use modals to send alerts, you can design a modal to your liking and it will look the same in all browsers.
Look, if you are looking to override full functionality over this method
( Alert() ; confirm () )
What you could do is override the function, directly what you do is overwrite said method.
Greetings.
Unfortunately you can't from the browser, you can only simulate one framework that I usually use for that is: Alertify JS
here is its documentation in english: alertifyjs
and here is a simple example:
if you want to see an example look here: examples
I recommend that you use the bootstrap framework to give your styles, I leave you an example:
Greetings.
Yes you can, but you have to step on the alert() and confirm() functions, an example I made for jQuery.
Where "msg" is the message you need and "type" is a simple class that you can use to paint the alert.
In the case of the Confirm it is the same, but add a button, the confirm are of type boolean (True or False).