jquery - Problems with Chaining in javascript -


i have following problem, i'm trying make small chained.

(function(window){ window.de=de={}  de.one=function(s){if(s){var y=document.getelementbyid(s); return y;} return this;}  de.two=function(s2){alert(s2); return this;}  })(window) 

this try to:

de.one("id").two("hello!"); 

but console gives me error:

typeerror: object # has no method 'two'

to give idea:

live demo

(function(window){  var mylibrary = (function( s ) {   var d = document,       e = d.getelementbyid( s ),       methods = {         1 : function(val){             alert(val);             return this; // maintain chainability         },          2 : function(val){             alert(val);             return this; // maintain chainability         },         css : function( property, val){             if(!val && typeof property == "object" ){ // styles in object notation                 for(var key in property){                     e.style[key] = property[key];                 }             }else{ // comma separated: property, value                 e.style[property] = val || undefined;             }             return this;             }     };     return methods;  }); window.mylibrary = window.de = mylibrary; // make window accept "de" "mylib" alias.     })(window); 

de("id").one("uga!!!").two("yoo").css({color:"red", background:"gold"}); 

taking in consideration have like:

 <div id="id">some element</div> 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -