admin管理员组文章数量:1389920
When ever I load a page with a very simple example I get
Uncaught TypeError: Cannot read property 'attachEvent' of null. Markdown.Editor.js:273
in my Chrome console log.
In Firebug I get
elem is null [Break On This Error]
if (elem.attachEvent) {
Markdo...itor.js (line 273)
Why am I getting those errors and how do I solve it?
When ever I load a page with a very simple example I get
Uncaught TypeError: Cannot read property 'attachEvent' of null. Markdown.Editor.js:273
in my Chrome console log.
In Firebug I get
elem is null [Break On This Error]
if (elem.attachEvent) {
Markdo...itor.js (line 273)
Why am I getting those errors and how do I solve it?
Share Improve this question edited May 25, 2012 at 16:07 user166390 asked May 25, 2012 at 15:53 Evan CarrollEvan Carroll 1 3-
null.attachEvent
<-- it's the same as this. Why doesn't that work, and why iselem
evaluating tonull
here? – user166390 Commented May 25, 2012 at 15:56 -
That
elem
evaluates tonull
and you should find out why. – user166390 Commented May 25, 2012 at 15:57 - 1 @pst I did find out why, the element doesn't exist yet if you run the javascript-wmd-initializing code in the HEAD. This is a self-answer question because Google shows a lot of people encountering the problem, and the only demo shows the code being executed at the end of the body -- not where people are likely to place it when they try to incorporate the library. – Evan Carroll Commented May 25, 2012 at 15:58
1 Answer
Reset to default 7Take a look at the code in the demo.
<script type="text/javascript">
(function () {
var converter1 = Markdown.getSanitizingConverter();
var editor1 = new Markdown.Editor(converter1);
editor1.run();
} );
</script>
See where it is located? At the end of the body. This means the elements already exist. However, you're probably loading this JavaScript in the head. Instead, put the code in a .ready() block, or put it back at the end of the body (or after the textarea in the DOM).
本文标签:
版权声明:本文标题:javascript - Using Pagedown I get "Uncaught TypeError: Cannot read property 'attachEvent' of null&q 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744653779a2617841.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论