{"id":15651,"date":"2016-05-23T20:30:20","date_gmt":"2016-05-23T20:30:20","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=15651"},"modified":"2018-11-14T05:02:35","modified_gmt":"2018-11-14T05:02:35","slug":"web-design-javascript-toggle","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/web-design-javascript-toggle\/","title":{"rendered":"Web Design:  JavaScript toggle"},"content":{"rendered":"<h1>The tutor continues from yesterday&#8217;s example of dynamic content.<\/h1>\n<p><script src=\"\/..\/javascripts\/changecolmay23.js\"><\/script><\/p>\n<p>In <a href=\"?p=15631\">yesterday&#8217;s post<\/a> I discussed how to change an element&#8217;s appearance on a page with JavaScript.  Today, I&#8217;ll discuss how to change it back and forth.<\/p>\n<p id=\"p0\" style=\"text-align:center;font-size:medium; font-family:arial;color:black\">This paragraph&#8217;s style can be toggled back and forth.<\/p>\n<p><button id=\"b0\" onclick=\"changecol0()\" style=\"display:block;margin:auto;background-color:brown;color:white\">Click here to toggle paragraph&#8217;s style.<\/button><\/p>\n<p>The mechanism of the toggle is a JavaScript <em>if<\/em> statement:<\/p>\n<p style=\"font-family:monospace\">var x = document.getElementById(&#8220;element&#8221;).style;<br \/>\nif (x==&#8221;teal&#8221;){<br \/>\nback to normal<br \/>\n}<br \/>\n<br \/>\nelse{<br \/>\nchange color to teal, background to yellow, font size, etc<br \/>\n}\n<\/p>\n<p>Source:<\/p>\n<p><a href=\"http:\/\/www.w3schools.com\/js\/js_htmldom_css.asp\">w3schools<\/a><\/p>\n<p><a href=\"http:\/\/www.dustindiaz.com\/seven-togglers\/\">dustindiaz.com<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor continues from yesterday&#8217;s example of dynamic content. In yesterday&#8217;s post I discussed how to change an element&#8217;s appearance on a page with JavaScript. Today, I&#8217;ll discuss how to change it back and forth. This paragraph&#8217;s style can be &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/web-design-javascript-toggle\/\"> <span class=\"screen-reader-text\">Web Design:  JavaScript toggle<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,837],"tags":[205,1614,1615],"class_list":["post-15651","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-web-design","tag-javascript","tag-javascript-change-style","tag-javascript-toggle"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/15651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=15651"}],"version-history":[{"count":28,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/15651\/revisions"}],"predecessor-version":[{"id":36161,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/15651\/revisions\/36161"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=15651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=15651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=15651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}