петък, юни 18, 2010

How to create jQuery function

Example: Create function setPosition(x,y) that will set top and left CSS properties of element:
jQuery.fn.setPosition = function(x, y) {
   this.css("position", "absolute");
   this.css("top", y);
   this.css("left", x);
   return this;
}

After that the function can be used like this:
$('#element').setPosition(100, 200);

Няма коментари: