This seems a little silly to even mention here, but some people don’t now how to actually trigger events for which they’ve sculpted all that nifty jQuery code functionality for.
It’s actually really simple to be honest. You know that $(‘#button’).click(function(){ alert(‘button clicked!’); }); code you just wrote into your page?
Well try running $(‘#button’).click(); – yes that’s right, the function you previously wrote just got triggered, didn’t it?
And this applies for most events which you create actions for. Calling the event function with a parameter basically means you are creating a handle for when that event is triggered. Calling the event function without any parameters is tantamount to triggering that event.
Simple, but missed by a surprisingly large amount of people! :)
You might also enjoy:
-
Before jQuery's native live() and delegate() functions came into being, the default for handling binding on late generated DOM elements was to make use of t ...
-
I stumbled upon this frankly excellent, though unfortunately generically named, jQuery color picker plugin the other day. Color Picker is a jquery plugin de ...
-
Sometimes you just don't want to use the good old anchor tag and want to use a tag instead, but at the same time, you want people who mouse-over your span ...
-
More than once I've found myself needing to add event handlers to controls (like labels for instance) that I am generating on the fly based on ever changing ...
-
The excellent and rather flexible jQuery plugin FancyBox has become my defacto jQuery lightbox implementation and as such it has found its way into most of ...