3

Duplicate: How would I implement StackOverflow's hovering dialogs?


I'm trying to create an error message, that is being displayed, so far here's a crude attempt, the message displays fine, however the click doesn't work..

function message(somemessage){
       $(document).ready(function(){
            $('<div class="error">' + somemessage+ '</div>')
           .insertAfter( $('#ErrorMessage') ).fadeIn('slow').animate({opacity: 1.0}, 5000).click(function(){$(this).remove});
   });
 }
Community
  • 1
  • 1
ra170
  • 3,643
  • 7
  • 38
  • 52

2 Answers2

10

I've already answered how to do this in this question.

If you want, just skip straight to the example.

However, if you want something more robust, you should check out the many solutions out there:

If you wanted to see how to do the other notifications used in this website (the ones at the top when you earn a new badge, etc) you can check out how to do that in this question.

Community
  • 1
  • 1
Paolo Bergantino
  • 480,997
  • 81
  • 517
  • 436
4

Isn't it because you forgot to add parenthesis after the remove function?

Try this

$('<div class="error">' + "somemessage"+ '</div>')
           .insertAfter( $('#ErrorMessage') ).fadeIn('slow').
animate({opacity: 1.0}, 5000).click(function(){$(this).remove()});
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169