A simple example for creating a jQuery function called setPosition which can be used to set the top and left CSS properties of an element.

1
2
3
4
5
6
jQuery.fn.setPosition = function(x, y) {
   this.css("position", "absolute");
   this.css("top", y);
   this.css("left", x);
   return this;
}

The function can be used like this:

1
$('#myid').setPosition(100, 200);