Reputation: 1126
Some objects in javascript can be appended a method to it.
For example we can have Array.prototype.pop = function() {...}
So what I wanna ask is that can we append a method to DOM elements?
Suppose I have the following
var x = document.getElementById("hello");
x.toggle();
How can I append a method called toggle
to DOM elements just like what we do in jquery??
Thank you so much.
Upvotes: 0
Views: 185
Reputation: 119867
In concept, you can append functions since DOM elements are Objects after all. In practice, however, you should avoid doing it. Circular references is one of the issues that is related to binding objects to DOM elements which can cause memory "leakage"
Upvotes: 1