Development Output

During script development authors frequently output values and results to themselves to make sure a script is doing its job properly as it progresses. There are several ways in which this is done.

console.log() method

 

This is trace output that is only available for viewing in a browser web console. Each log is put on a new line in the console. This approach is preferable if there will be multiple outputs logged, or when you do not want output to interfere with how the application runs.

alert() method

 

This method renders a small dialog window that can show output. A web console does not have to be open to see this output. It is also used in live applications to alert users with messages they must see. alert( "some value" );

document.write() method

 

This method is intended to be used to write web content within the <body> element of a web document. If used outside of the body element you will get an “unbalanced tree” warning in the web console, but the temporary output will be gone as soon as the application moves along. You can view dynamic HTML output directly in the document using this approach. document.write( "some value" );

element.innerHTML property

Authors may put an element in the document and give it an id attribute. Output can be rendered into this element’s innerHTML content during development for testing purposes. Authors can choose to target element.textContent property instead of element.innerHTML property.

 

<h2 id="status">

 

0

 

</h2>

 

<script>

 

var pos = 0;

 

setInterval

 

( function(){ pos++; document.getElementById("status").innerHTML = pos; }, 1000 );

 

</script>

renewdev

I Am Developer And Want To Share My Knowledge With The World..:) ;) . I Have Another Social Networking Website (Renewchat) And For Designing Or Developing Of Website Purpose You Can Contact Me On Renew Coder .. :) ;)

Leave a Reply

Your email address will not be published. Required fields are marked *