I am struggling trying to find a way to create an alert that opens when you click a button and then should disappear after an amount of time that can be set as a parameter.
so far I have this:
<script>
function myFunction() {
alert("I will think later what to write here");
}
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".item_add").click(function(){
myFunction();
});
});
</script>
How should I change the code to achieve the result?
Thank you all for the help!
You need to build the dialog yourself using HTML elements.
After this is done you should check
setTimeout()
that will allow you to perform a function after a preset period of time - e.gvisibility:hidden
your custom dialog.Since you are using jQuery you can substitute the
visibility
toggling for a$('#custom-alert-1').fadeOut()
which provides a more streamlined show/hide effect.If you are talking about the 'native'
alert()
then that won't ever work as JS does not have any access to it in any way apart from popping it open