I want to create a plugin 'myPlugin' which simply add some text to a div. like:
document.getElementById('testDiv').myPlugin("this is a text");
how can I achieve this through singleton method as well as prototype method ?
I want to create a plugin 'myPlugin' which simply add some text to a div. like:
document.getElementById('testDiv').myPlugin("this is a text");
how can I achieve this through singleton method as well as prototype method ?
HTMLElement.prototype.myPlugin = function(t) {
// ...
}
Will add a method to all HTML elements in compliant browsers. It won't work on IE though (at least on the old versions, I honestly haven't tried in IE8).
What do you mean by "singleton method"?