Print / display a JavaScript variable’s name instead of it’s value

You can put the variables in an object then easily print them this way: http://jsfiddle.net/5MVde/7/ See fiddle for everything, this is the JavaScript… var x = { foo: 5, bar: 6, foobar: function (){ var that=this; return that.foo+that.bar } }; var myDiv = document.getElementById(“results”); myDiv.innerHTML=’Variable Names…’; for(var variable in x) { //alert(variable); myDiv.innerHTML+='<br>’+variable; } myDiv.innerHTML+='<br><br>And … Read more

What is the correct way to write HTML using Javascript?

document.write() will only work while the page is being originally parsed and the DOM is being created. Once the browser gets to the closing </body> tag and the DOM is ready, you can’t use document.write() anymore. I wouldn’t say using document.write() is correct or incorrect, it just depends on your situation. In some cases you … Read more

Execute write on doc: It isn’t possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

An asynchronously loaded script is likely going to run AFTER the document has been fully parsed and closed. Thus, you can’t use document.write() from such a script (well technically you can, but it won’t do what you want). You will need to replace any document.write() statements in that script with explicit DOM manipulations by creating … Read more