简体   繁体   English

如何在npm模块中访问dom

[英]how to access dom in npm module

I am writing a NPM package and I want to write something to the DOM inside my function. 我正在编写一个NPM包,并且想在我的函数内向DOM写一些东西。 But I get an error saying the document is not defined example, 但是我收到一个错误消息,说该文档未定义示例,

foo package: foo软件包:

module.exports = {
    sayHello: function(){
        document.getElementByID('#hello').innerHTML('Hello');
    }
}

In client-side javascript: 在客户端javascript中:

import { sayHello } from 'foo';
$('#myButton').click(() => sayHello());

First of all there is a typo at 首先有一个错字

document.getElementByID

The correct spelling is 正确的拼写是

document.getElementById

Besides that the question may be a duplicate of this question 除此之外,这个问题可能是这个问题的重复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM