Try something like this:
EDIT :
Changed Shake() to Shake() for consistency with jQuery conventions.
jQuery.fn.shake = function() { this.each(function(i) { $(this).css({ "position": "relative" }); for (var x = 1; x <= 3; x++) { $(this).animate({ left: -25 }, 10).animate({ left: 0 }, 50).animate({ left: 25 }, 10).animate({ left: 0 }, 50); } }); return this; }
EDIT :
In my example, the left position is set to 25 , but you can reduce it for a finer effect or increase it for a more pronounced effect.
Using the shake function:
$("#div").shake();
Here's a jsFiddle that demonstrates this: http://jsfiddle.net/JppPG/3/
source share