You can use the plug-in architecture to make it easier:

$.fn.addBehaviour = function(id, callback) {

    return this.click(function(){
         var url = //create url
         $.ajax({
             url: url,
             success: callback
          });
     });
};

in this case you don't use the keyword 'new' because you pass a
function.

- ricardo

On Oct 23, 1:10 pm, Justin <[EMAIL PROTECTED]> wrote:
> I'm new to jquery and I'm writing some code but I'd like to make sure
> I'm not rewriting something that already exists. Basically, I'd like
> to be able to do:
>
> $("#myAnchor").addBehavior($("#targetDiv", new MyNewBehavior);
>
> I implement a few functions for MyNewBehavior such as "buildURL"
> and "stuffToDoAfter". When myAnchor is clicked on, an ajax request is
> made to buildUrl (which might be a static URL or might build the URL
> from parameters), then targetDiv is filled with the html fragment that
> is sent to the "success" function, and finally stuffToDoAfter() is
> executed in case you want to manipulate the newly added elements.
>
> So it abstracts away the click() call, the ajax call, the
> targetDiv.innerHTML = ajaxResponse, etc.
>
> Anyone know if something like this already exists?

Reply via email to