I am trying to extend the DOM. I am "subclassed" from a div element:
var Subclass = function() {} Subclass.prototype = document.createElement('div'); Subclass.constructor = Subclass; var obj = new Subclass(); var obj.innerHTML = 'test'; document.body.appendChild(obj); // Exception: Node cannot be inserted ... point in the hierarchy
So, if the prototype of the object being the DOM object fails, what is the requirement to insert the object into the DOM?
It really works in Firefox .. Anyway. In fact, it will not create new elements when creating a new subclass, but will continue to use the same.
In any case, I would say that the DOM objects themselves are "special" in the sense that only they can be appendChild'd.
According to the W3C specification appendChild():
appendChild()
Node
DOMException
:
Node appendChild(in Node newChild) raises(DOMException);
if you want to expand only div elements, maybe you can do it with
HTMLDivElement.prototype.newFunction = function () { //'this' will get that div dom }
then it will expand only div elements. Works on FF, doesn't know about other browsers.
Hope this can help you.
Source: https://habr.com/ru/post/1783788/More articles:Opcode and ModRM for the 'call dword ptr [mem32]' question? - assemblyNeed to remove new lines from object / embed tags only with Nokogiri - ruby โโ| fooobar.comError opening serial port in C # - c #Is it possible to store a sqlite database containing 333,000 rows locally on iPhone / iPod Touch? - sqliteJQuery UI datipicker parameters as variables - javascriptNested types or another solution for one mapped class - designHow can I write a python function to accept * arguments and a keyword argument? - pythonFind symbolic links in a directory - findedit the routing form - when updating submit starts the #show method instead of #update - ruby-on-railsThe wpf dragenter / dragleave problem - wpfAll Articles