Just a note, since you got the answer already...

I was under the impression that .click() is or is going to be deprecated at some point (as we are trying to move away from all the rather unnecessary shortcuts that clutter the API). The shortcuts also cause confusion. For example the jQuery focus() function is actually a shortcut for for binding a function to execute onFocus, rather than setting a focus to an element (which is what the DOM method does). Another confusing example seems to be the .load() -method, which does two entirely different things depending on the parameters. With only a single function as a parameter it works as a binder for attaching functions to the load event of an element, whereas with more parameters it works as the better known method for loading remote HTML through XHR and inserting it to the DOM. Then on top of these problems there are the triggerings. .click() without parameters triggers a click-event, and with parameters it binds stuff to the event.

So even if the shortcuts were created to help new users, in the end I think they can end up hurting and confusing them even more. Especially since these are not totally consistent (see .load() above

IMO the cleanest route by far is to just keep using .bind() and .trigger() for binding and triggering events respectively.

So the preferred format would be to use
$().bind('click',function(){ ... });
(see http://jquery.bassistance.de/api-browser/#bindStringObjectFunction)

It also looks more consistent, with all the bindings done through the same function (and its much easier to find all the bindings in the code).

It also works for the other shortcuts, so
$().bind('mouseover',function(){ ... });
$().bind('focus',function(){ ... });

--
Suni

Brian Ronk wrote:
I wanted to look something up, but since the site is moving hosts
right now, that makes it a little hard :)
is click() an available function?  I wanted to add an event to a div
that made an area visible to do some editing.  I know I could just to
an onclick method, but I wanted to try adding something dynamically to
see what I could do, and if it was what I wanted. Thanks.

Reply via email to