I have been wondring how i can create functions like jQuery of the style
where the $(ID).function() is called when the html element is painted
What you're looking for is method/function chaining or alternatively cascades. The methods in the chain need to return this.
I'm sure there's many more.