0

as I am a beginner in coding and just started learning objects, I have difficulties calling a function with objects as properties. I am trying to develop a text based game with html, js and would like to do this without jQuery as I really want to understand js first (Don't know if this is recommended :p ). Anyhow, here is the code, that shows the error "Uncaught TypeError: Cannot read property 'insertBefore' of null":

var x;
function addText(x) {
  var newParagraph = document.createElement('P');
  var newText = document.createTextNode(x);
  newParagraph.appendChild(newText);

  var textGame = document.getElementById("textInsert");
  textGame.insertBefore(newParagraph, textGame.childNodes[0]);
};

addText(frameStory.feelVeryCold.msg);

As you see I want to call the object "frameStory.feelVeryCold.msg", which is a simple string with the function addText.

It is my first post here, so I hope I gave you all the relevant information, I am appreciating any help I can get, thanks guys :)

Robstaa
  • 33
  • 5

0 Answers0