{"id":94,"date":"2019-01-02T02:34:45","date_gmt":"2019-01-02T02:34:45","guid":{"rendered":"https:\/\/people.utm.my\/zuraida\/?p=94"},"modified":"2019-01-02T02:34:45","modified_gmt":"2019-01-02T02:34:45","slug":"javascript-output","status":"publish","type":"post","link":"https:\/\/people.utm.my\/zuraida\/2019\/01\/02\/javascript-output\/","title":{"rendered":"JavaScript Output"},"content":{"rendered":"<h2>Using innerHTML<\/h2>\n<p>To access an HTML element, JavaScript can use the <strong>document.getElementById(id)<\/strong> method.<\/p>\n<p>The <strong>id<\/strong> attribute defines the HTML element. The <strong>innerHTML<\/strong> property defines the HTML content:<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;h2&gt;My First Web Page&lt;\/h2&gt;<br \/>\n&lt;p&gt;My First Paragraph.&lt;\/p&gt;<\/p>\n<p>&lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<br \/>\ndocument.getElementById(&#8220;demo&#8221;).innerHTML = 5 + 6;<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h2>Using document.write()<\/h2>\n<p>For testing purposes, it is convenient to use <strong>document.write()<\/strong>:<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;h2&gt;My First Web Page&lt;\/h2&gt;<br \/>\n&lt;p&gt;My first paragraph.&lt;\/p&gt;<\/p>\n<p>&lt;p&gt;Never call document.write after the document has finished loading.<br \/>\nIt will overwrite the whole document.&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<br \/>\ndocument.write(5 + 6);<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h2>Using window.alert()<\/h2>\n<p>You can use an alert box to display data:<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;h2&gt;My First Web Page&lt;\/h2&gt;<br \/>\n&lt;p&gt;My first paragraph.&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<br \/>\nwindow.alert(5 + 6);<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h2>Using console.log()<\/h2>\n<p>For debugging purposes, you can use the <strong>console.log()<\/strong> method to display data.<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;h2&gt;Activate debugging with F12&lt;\/h2&gt;<\/p>\n<p>&lt;p&gt;Select &#8220;Console&#8221; in the debugger menu. Then click Run again.&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<br \/>\nconsole.log(5 + 6);<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using innerHTML To access an HTML element, JavaScript can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content: &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h2&gt;My First Web Page&lt;\/h2&gt; &lt;p&gt;My First Paragraph.&lt;\/p&gt; &lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt; &hellip; <a href=\"https:\/\/people.utm.my\/zuraida\/2019\/01\/02\/javascript-output\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":14456,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/users\/14456"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":0,"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/people.utm.my\/zuraida\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}