I've seen a few modules use the feature where they have a message displayed, but they allow you to close it by click 'X' on top right. And it simply fades away/hides using JS. (Can't remember which modules, otherwise I'd have looked at their code, and nor can I frame this question right on Google?)

Can I do this using drupal_set_message? I don't think it provides that functionality, as it takes only 3 params and none correspond to that.

How do others do that, because I think it's actually a better feature UI experience, than having to refresh the page to remove the message.

I'm guessing it's by simple js, if people have used in Drupal, can you share the code?

Super awesome points, if any one has figured out a way to wrap this around any drupal_set_message. Because that'd be so cool!

**** UPDATE *****

We figured out a way to do that, but forgot to post it.

In js,

(function ($) {
  $(document).ready(function() {
    $('.messages').prepend("<div class='close-button'></div>");
    $('.messages .close-button').click(function() {

In the theme css file

.messages .close-button {
position: absolute;
right: 10px;
top: 5px;
width: 20px;
height: 20px;
background: url("../images/close_button.png") 50% 50% no-repeat;
cursor: pointer;
-ms-border-radius: 100%;
-o-border-radius: 100%;
-moz-border-radius: 100%;
-webkit-border-radius: 100%;
border-radius: 100%; }

.messages .close-button:hover {
  background-color: rgba(255, 186, 186, 0.38); }
  • Sorry but this too broad for the Q+A format here. Requests for code to be written are off-topic for various reasons, not least because we don't have code-writing service here :) Requesting links to off-site resources is also a no-no, simply because it's not a good fit for our format. There's a list of status message modules that you can browse, and check out the code. If you get specific Drupal (i.e. not JS syntax) problems implementing the code from those, please just edit the question with that information and flag it for re-opening. Many thanks
    – Clive
    Nov 7 '13 at 10:28
  • BTW the simple answer for whether drupal_set_message() has this functionality is no, is doesn't; if you've seen that sort of functionality somewhere it's been added by a theme/module using CSS/JS, not by core
    – Clive
    Nov 7 '13 at 10:28
  • Nope, you cannot. drupal_set_message is only that - a setter for the message. Now, in your module or your theme you can provide template for message, and a JavaScript interacting with that template.
    – Mołot
    Nov 7 '13 at 10:29
  • probably you are looking for this module drupal.org/project/better_messages
    – Bala
    Nov 7 '13 at 10:45
  • 1
    @Clive it have the option to use drupal_set_message() with the help of drupal.org/project/purr_messages module, here is the example tanc.me/purr-messages-demo. Is any possibilities to post this as answer.
    – Bala
    Nov 7 '13 at 10:49