How to use Drupal.behaviors? I am trying to do a simple ajax request when the document is ready. Along with that, I also want to provide a function that is an onclick event.

Here is my code:

(function ($) {

  Drupal.behaviors.user_alert_get_message = {
    attach: function(context, settings) {

            $.ajax({
               type: "GET",
               url: "/admin/user-alert/get-message",
               success: function(data){
                   $('div#block-user-alert-user-alert').html(data);
               }
             });

        $('div.user-alert-close a', context).click(function() {
          alert(1);
        });
    }
  };
}(jQuery));


The click function does not fire. The ajax does. What can I wrap the ajax in so it only does this on page load, or, is that assumed through attach?

I also tried an onclick on the a tag, but Firebug said the function was undefined, even when it was defined as function (function name) in the .js file.

Edit:

If you have a click event that accepts an argument, how can I pass that in?
As I understood it, Drupal.behaviors attach would allow the .click to fire on an element created at anytime. But just in case, I would try using .delegate(), as in 

$('body').delegate('div.user-alert-close a', 'click', function() {
  alert(1);
});