Using Pagedown, I get "Uncaught TypeError: Can't read the" attachEvent "property from null"

When I load a page with a very simple example, I get

Uncaught TypeError: Unable to read the 'attachEvent' property from 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 these errors and how to solve them?

+6
source share
1 answer

Take a look at the code in demo .

 <script type="text/javascript"> (function () { var converter1 = Markdown.getSanitizingConverter(); var editor1 = new Markdown.Editor(converter1); editor1.run(); } ); </script> 

See where it is? At the end of the body. This means that the elements already exist. However, you are probably loading this JavaScript in your head. Instead, put the code in a block . Ready () or return it to the end of the body (or after the text field in the DOM).

+7
source

Source: https://habr.com/ru/post/916687/


All Articles