function stop works when inside class JavaScript

Colate

New Member
I have this function that reads coordination from a XML file, the function works fine when its loose in the window. but when I put it inside a function, then I get the error. Cannot read property 'style' of null. on row 127.row 127 is\[code\]document.getElementById(id).style.top=Ynod;\[/code\]Any ideas ?\[code\]var main = (function () {var id=Math.floor((Math.random()*1000000)+1);document.getElementById("add-new-sticker-btn").addEventListener("click", function(){ id += 1; console.log(id); add_sticker(""); /**"" removes undefined "*/ var xmlhttp; xmlhttp=new XMLHttpRequest(); xmlhttp.open("POST","/project2/php/insert.php",true); /*Search way... JS to javaScript*/ xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("textBoxID="+id);});function run(){loadStickers();}function loadStickers(){ /* works witout the loadSticker() function ? */ var xmlhttp; xmlhttp = new XMLHttpRequest(); xmlhttp.open("get", 'xml/stickers.xml', false); xmlhttp.send(); var myXML = xmlhttp.responseXML; stickers = myXML.getElementsByTagName("sticker"); for (i = 0; i < stickers.length; i++) { var idNod = (stickers.getElementsByTagName("id")[0].childNodes[0].nodeValue); /*Get the ID*/ var id = idNod; var textNod = (stickers.getElementsByTagName("text")[0].childNodes[0].nodeValue); /* Text*/ add_sticker(textNod); /*Call creator function*/ var Xnod = (stickers.getElementsByTagName("x")[0].childNodes[0].nodeValue) + 'px'; /*Get the x position Add PX for pixel*/ var Ynod = (stickers.getElementsByTagName("y")[0].childNodes[0].nodeValue) + 'px'; /*Get the y position*/ var Znod = (stickers.getElementsByTagName("z")[0].childNodes[0].nodeValue); /*Get the y position*/ console.log(Ynod) // Gives correct Y and X console.log(Xnod) document.getElementById(id).style.top = Ynod; document.getElementById(id).style.left = Xnod; document.getElementById(id).style.zIndex = Znod; }}window.addEventListener("load", run);return {};}());\[/code\]You can see the project with the error message in the console.http://felipeotarola.se/project2/
 
Back
Top