Using Pagedown I get “Uncaught TypeError: Cannot read property 'attachEvent' of null”

StackOverflow https://stackoverflow.com/questions/10757630

  •  11-06-2021
  •  | 
  •  

Domanda

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?

È stato utile?

Soluzione

Take 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).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top