How to add custom function to call after document.getElementById?

依然范特西╮ 提交于 2021-02-04 19:09:34

问题


I'm just curious, how can I call a custom function after document.getElementById()? Something like this:

document.getElementById("element").mycustomfunction();

回答1:


Technically you can do this :

Element.prototype.mycustomfunction = function() {
     console.log("I don't work on IE7");
};

You can test it easily in your console on this page : type it first and then document.getElementById("notify-container").mycustomfunction();.

It works. There's not technical problem with it. But it might make it a little harder for maintainers of your applications to trace what happens, it might led to collisions with other plugins doing the same, and it doesn't really add a lot over myPlugin.doSomething(element).



来源:https://stackoverflow.com/questions/16752928/how-to-add-custom-function-to-call-after-document-getelementbyid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!