{"id":168,"date":"2026-01-12T16:40:06","date_gmt":"2026-01-12T21:40:06","guid":{"rendered":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/?post_type=chapter&#038;p=168"},"modified":"2026-02-18T13:41:53","modified_gmt":"2026-02-18T18:41:53","slug":"chapter-11-javascript","status":"publish","type":"chapter","link":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/chapter\/chapter-11-javascript\/","title":{"raw":"Chapter 11 \u2022\u00a0JavaScript","rendered":"Chapter 11 \u2022\u00a0JavaScript"},"content":{"raw":"<h2>What is JavaScript?<\/h2>\r\nJavaScript is the programming language for the web. JavaScript can be included in tags, such as buttons, or written as separate functions that are \"called\" from a tag.\r\n\r\nMany practical functions can be implemented with JavaScript, including printing the page, increasing type size to improve legibility, increasing contrast, and controlling animations.\r\n\r\nJavaScript is a separate language from HTML\/CSS that many designers consider to be difficult. However numerous simple JavaScript functions can be written with the help of AI chat programs.\r\n<h2>Sample Code<\/h2>\r\nExample of a JavaScript statement included in the &lt;button&gt; tag:\r\n<pre>&lt;button onClick=\"window.print();\"&gt;Print Page&lt;\/button&gt;<\/pre>\r\nExample of the above statement placed in a function:\r\n<pre>&lt;script&gt;\r\n    function printPage() {\r\n        window.print();\r\n    }\r\n&lt;\/script&gt;\r\n<\/pre>\r\n. . . And calling the function in a button:\r\n<pre>&lt;button onClick=\"printPage()\"&lt;Print Page&gt;\r\n<\/pre>\r\n<h2>Using AI to Write JavaScript<\/h2>\r\nAI chat programs like ChatGPT, ChatAI, DeepSeek, and others make JavaScript more accessible to non-programmers. The key to getting functional JavaScript is to write an accurate, detailed prompt. The following prompt was used to write a program to enlarge thumbnail images when clicked:\r\n<div style=\"width: 100%;background: whitesmoke;padding: 12px;margin: 6px auto\">Write a JavaScript program and CSS styles for an HTML web page in which a small thumbnail image, when clicked, opens a larger image that sits in front of the page and includes a cancel \"X\" button.<\/div>\r\n<h2>jQuery JavaScript Library<\/h2>\r\n<a href=\"https:\/\/jquery.com\" target=\"_blank\" rel=\"noopener\">jQuery<\/a> is a free library of JavaScript functions hosted by Massachusetts Institute of Technology's Media Lab. According to Wikipedia, jQuery is used in 77% of the 10 million most popular web sites.\r\n\r\nTwo ways to implement jQuery are to (1) link to the jQuery library at code.jquery.com, or (2) download the jQuery library to your computer and link to it on your server.\r\n\r\nSome jQuery functions include fade-in\/fade-out, slide-down\/slide-up, change class, animate, sortable, and draggable.\r\n<table id=\"javascript-thumbs\" style=\"border-collapse: collapse;width: 100%;border: none;background: none\" border=\"0\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 33.333333%\">\r\n\r\n[caption id=\"attachment_171\" align=\"alignright\" width=\"175\"]<a href=\"https:\/\/adamsr12.github.io\/grc365\/javascript-demo.html\"><img src=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-238x300.jpg\" alt=\"\" width=\"175\" height=\"221\" class=\"wp-image-171\" style=\"border: 1px solid darkgray;box-shadow: 2px 3px 6px darkgray\" \/><\/a> These three pages include some practical examples of JavaScript functions, including enlarging some photos, printing the page, increasing type size, and checking all boxes in a form.[\/caption]<\/td>\r\n<td style=\"width: 33.333333%\">\r\n\r\n[caption id=\"attachment_179\" align=\"aligncenter\" width=\"175\"]<a href=\"https:\/\/r3adams.github.io\/grc365\/jquery.html\"><img src=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-236x300.jpg\" alt=\"\" width=\"175\" height=\"222\" class=\"wp-image-179\" \/><\/a> This jQuery tutorial shows the functions fade-in\/fade-out, slide-up\/slide-down, change class, animate, sortable, and draggable.[\/caption]<\/td>\r\n<td style=\"width: 33.333333%\">\r\n\r\n[caption id=\"attachment_172\" align=\"alignleft\" width=\"175\"]<a href=\"https:\/\/r3adams.github.io\/grc-365-new\/javascript.html\"><img src=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-620x1024.jpg\" alt=\"\" width=\"175\" height=\"289\" class=\"wp-image-172\" style=\"border: 1px solid darkgray;box-shadow: 2px 3px 6px darkgray\" \/><\/a> This sample page shows two examples of jQuery JavaScript functions, \"sortable\" and \"draggable,\" each implemented with one line of code.[\/caption]<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<div style=\"width: 100%;margin: 0 auto;background: whitesmoke\"><\/div>","rendered":"<h2>What is JavaScript?<\/h2>\n<p>JavaScript is the programming language for the web. JavaScript can be included in tags, such as buttons, or written as separate functions that are &#8220;called&#8221; from a tag.<\/p>\n<p>Many practical functions can be implemented with JavaScript, including printing the page, increasing type size to improve legibility, increasing contrast, and controlling animations.<\/p>\n<p>JavaScript is a separate language from HTML\/CSS that many designers consider to be difficult. However numerous simple JavaScript functions can be written with the help of AI chat programs.<\/p>\n<h2>Sample Code<\/h2>\n<p>Example of a JavaScript statement included in the &lt;button&gt; tag:<\/p>\n<pre>&lt;button onClick=\"window.print();\"&gt;Print Page&lt;\/button&gt;<\/pre>\n<p>Example of the above statement placed in a function:<\/p>\n<pre>&lt;script&gt;\r\n    function printPage() {\r\n        window.print();\r\n    }\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>. . . And calling the function in a button:<\/p>\n<pre>&lt;button onClick=\"printPage()\"&lt;Print Page&gt;\r\n<\/pre>\n<h2>Using AI to Write JavaScript<\/h2>\n<p>AI chat programs like ChatGPT, ChatAI, DeepSeek, and others make JavaScript more accessible to non-programmers. The key to getting functional JavaScript is to write an accurate, detailed prompt. The following prompt was used to write a program to enlarge thumbnail images when clicked:<\/p>\n<div style=\"width: 100%;background: whitesmoke;padding: 12px;margin: 6px auto\">Write a JavaScript program and CSS styles for an HTML web page in which a small thumbnail image, when clicked, opens a larger image that sits in front of the page and includes a cancel &#8220;X&#8221; button.<\/div>\n<h2>jQuery JavaScript Library<\/h2>\n<p><a href=\"https:\/\/jquery.com\" target=\"_blank\" rel=\"noopener\">jQuery<\/a> is a free library of JavaScript functions hosted by Massachusetts Institute of Technology&#8217;s Media Lab. According to Wikipedia, jQuery is used in 77% of the 10 million most popular web sites.<\/p>\n<p>Two ways to implement jQuery are to (1) link to the jQuery library at code.jquery.com, or (2) download the jQuery library to your computer and link to it on your server.<\/p>\n<p>Some jQuery functions include fade-in\/fade-out, slide-down\/slide-up, change class, animate, sortable, and draggable.<\/p>\n<table id=\"javascript-thumbs\" style=\"border-collapse: collapse;width: 100%;border: none;background: none\">\n<tbody>\n<tr>\n<td style=\"width: 33.333333%\">\n<figure id=\"attachment_171\" aria-describedby=\"caption-attachment-171\" style=\"width: 175px\" class=\"wp-caption alignright\"><a href=\"https:\/\/adamsr12.github.io\/grc365\/javascript-demo.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-238x300.jpg\" alt=\"\" width=\"175\" height=\"221\" class=\"wp-image-171\" style=\"border: 1px solid darkgray;box-shadow: 2px 3px 6px darkgray\" srcset=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-238x300.jpg 238w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-811x1024.jpg 811w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-768x969.jpg 768w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-1217x1536.jpg 1217w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-65x82.jpg 65w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-225x284.jpg 225w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript-350x442.jpg 350w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/completed-tutorials-javascript.jpg 1572w\" sizes=\"auto, (max-width: 175px) 100vw, 175px\" \/><\/a><figcaption id=\"caption-attachment-171\" class=\"wp-caption-text\">These three pages include some practical examples of JavaScript functions, including enlarging some photos, printing the page, increasing type size, and checking all boxes in a form.<\/figcaption><\/figure>\n<\/td>\n<td style=\"width: 33.333333%\">\n<figure id=\"attachment_179\" aria-describedby=\"caption-attachment-179\" style=\"width: 175px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/r3adams.github.io\/grc365\/jquery.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-236x300.jpg\" alt=\"\" width=\"175\" height=\"222\" class=\"wp-image-179\" srcset=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-236x300.jpg 236w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-806x1024.jpg 806w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-768x976.jpg 768w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-1209x1536.jpg 1209w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-65x83.jpg 65w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-225x286.jpg 225w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial-350x445.jpg 350w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/jQuery-tutorial.jpg 1544w\" sizes=\"auto, (max-width: 175px) 100vw, 175px\" \/><\/a><figcaption id=\"caption-attachment-179\" class=\"wp-caption-text\">This jQuery tutorial shows the functions fade-in\/fade-out, slide-up\/slide-down, change class, animate, sortable, and draggable.<\/figcaption><\/figure>\n<\/td>\n<td style=\"width: 33.333333%\">\n<figure id=\"attachment_172\" aria-describedby=\"caption-attachment-172\" style=\"width: 175px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/r3adams.github.io\/grc-365-new\/javascript.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-620x1024.jpg\" alt=\"\" width=\"175\" height=\"289\" class=\"wp-image-172\" style=\"border: 1px solid darkgray;box-shadow: 2px 3px 6px darkgray\" srcset=\"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-620x1024.jpg 620w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-182x300.jpg 182w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-768x1268.jpg 768w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-65x107.jpg 65w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-225x372.jpg 225w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript-350x578.jpg 350w, https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-content\/uploads\/sites\/449\/2026\/01\/demo-site-javascript.jpg 930w\" sizes=\"auto, (max-width: 175px) 100vw, 175px\" \/><\/a><figcaption id=\"caption-attachment-172\" class=\"wp-caption-text\">This sample page shows two examples of jQuery JavaScript functions, &#8220;sortable&#8221; and &#8220;draggable,&#8221; each implemented with one line of code.<\/figcaption><\/figure>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"width: 100%;margin: 0 auto;background: whitesmoke\"><\/div>\n","protected":false},"author":6,"menu_order":11,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-168","chapter","type-chapter","status-publish","hentry"],"part":3,"_links":{"self":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/chapters\/168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/wp\/v2\/users\/6"}],"version-history":[{"count":21,"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/chapters\/168\/revisions"}],"predecessor-version":[{"id":227,"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/chapters\/168\/revisions\/227"}],"part":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/chapters\/168\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/wp\/v2\/media?parent=168"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/pressbooks\/v2\/chapter-type?post=168"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/wp\/v2\/contributor?post=168"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/webdesign2\/wp-json\/wp\/v2\/license?post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}