adi rohan adi rohan - 1 year ago 89
jQuery Question

Add methods to function

I want to add method to a function such that i can call them in a chain

What i want to do:

If you have used jQuery , then you must have seen the syntax like


returns element


returns css value of property of element

How can i do it by defining custom methods with same syntax without using jQuery ?

Answer Source

Here is a simple one:

function Get( element_id ) {
    this.node = document.querySelector(element_id);
    this.css = function(prop, val) {};

var get = function( element_id )
    return new Get( element_id );

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download