I have a simple library to select an element and return the object of element.
(function() {
var $ = function(parameter) {
return new js(parameter);
};
var js = function(parameter) {
var selector;
selector = document.getElementById(parameter);
this = selector; // assign selector to this.
return this;
};
// Extend the library.
$.fn = js.prototype = {
hide: function() {
this.style.display = 'none';
return this;
}
};
if (!window.$) {
window.$ = $;
}
})();
When I use it.
HTML
<div id="box"> Hello world! </div>
Javascript
$('box').innerHTML = "Good";
Note: I want to do like this create a simple JavaScript library
What is the problem that prevent run the code ?