For example, there is an object V which takes an element id, class or a tag name as a parameter and applies functions on it, like so.
var V = function(elem) {
// logic to getElementBy ID or class or tag name and return it
if(type === '#') {
// get by id
domElem = document.getElementById(elem.slice(1));
} else if(type === '.') {
// get by class
domElem = document.getElementsByClassName(elem.slice(1));
} else if(typeof type === 'string' && (type !== '#' || type !== '.')) {
// get by elem type
domElem = document.getElementsByTagName(elem);
}
return domElem;
}
So now when you get an element, like so: var myDiv = V('#someDivElement');
it will return you the div element. Now, I also run a method on the returned object. For example, I want to run a method asdf that simply appends a paragraph tag inside the div, like so:
V.prototype.asdf = function() {
this.appendChild('<p>I am an awesome child!</p>');
return this;
}
Ideally, it works when I do:
var myDiv = V('#someDivElement');
But the below line doesn't seem to execute.
myDiv.asdf();
What am I doing wrong here?