Note: divalert() still works great, but it is getting a bit old. I rarely work in
using one of the many excellent libraries such as jQuery to deal with
browser incompatibilities and such. Having said that, if you're looking for a small, lightweight utility,
by all means, give divalert a try!
-Dave (Jan 1, 2011)
A Quick Example
My divalert() function works just like alert, but displays its contents in the web page in a <div> tag (click on the statement to try it!):
What makes this better? Well, for one thing, you don't have to click "OK" anywhere to keep using the page (on the rare occasions where you do need that behavior, by all means use alert()). Another big improvement is that any new alerts are also displayed in a running log.
Installing and using divalert is very simple. First, Grab divalert.js here.
Then, include it in your page like so:
Now that you've installed divalert, simply call it as you would with alert():
One final thing you can do when calling divalert() is to call for a bold alert. Simply call divalert with "true" as your second parameter (click on the statement to try it!):
Besides just being kinda old, there are some minor known problems with divalert():
- You cannot display arbitrary HTML using plain divalert(). I was asked by a Moodle user to add this feature, which I did by making a new version of divalert that uses jQuery. If you're insterested, just contact me.
- divalert() doesn't deal well with scrolling. Sorry, it currently just pops up near the top of the page, even if that's above where you're currently scrolled. You can drag it around to some degree, though.