{"id":752,"date":"2012-10-05T16:36:45","date_gmt":"2012-10-05T16:36:45","guid":{"rendered":"http:\/\/a.parsons.edu\/~dejongo\/12-fall\/?p=752"},"modified":"2021-04-19T16:09:42","modified_gmt":"2021-04-19T16:09:42","slug":"12-javascriptjquery","status":"publish","type":"post","link":"https:\/\/b.parsons.edu\/~dejongo\/12-javascriptjquery\/","title":{"rendered":"11 JavaScript\/JQuery"},"content":{"rendered":"<p>If HTML is for content and CSS for presentation, than Javascript is for behavior. It really takes mastery of all three to become a web designer. It is, unfortunately,  too much for this coures to tackle all three, so we merely touch on Javascript and give you some idea of how it works.  If you want to learn more, try <a href=\"https:\/\/www.khanacademy.org\/computing\/computer-programming\">Kahn Academy <\/a> or Codecademy for <a href=\"http:\/\/www.codecademy.com\/en\/tracks\/javascript\"> Javascript<\/a> or <a href=\"http:\/\/www.codecademy.com\/tracks\/jquery\">Jquery<\/a>.\n<\/p>\n<p>Javascript goes as far back as the origin of the web. You will <a href=\"01-history-of-the-web\/\">recall<\/a> that the web was inspired by Apple&#8217;s Hypercard, which had been implemented in a proto-web kind of way in the offices where the web was born. Well, hypercard had a scripting language called Hyperscript that inspired Javascript.\n<\/p>\n<p>Javascript transforms the content of web pages in much the same way as HyperScript transformed the content of the hypercard stacks. Javascript scripts are executed upon loading or by a user action, and do something to the content of the web page. Much of the added functionality on the web is due to Javascript.<\/p>\n<h2>Where Javascript Enters the Picture<\/h2>\n<\/p>\n<p>When the browser requests content from the server, the document is fetched or constructed by server side scripting, crosses the HTTP divide, and arrives at the client (the browser). The browser then parses the content, starting with the header, and constructs the document, including the requests for additional resources such as the CSS stylesheet, JavaScript scripts, fonts, and images, and organizes all of it into the web page we are all familiar with. In the case of Ajax, additional material can be requested and received without flushing the existing page, allowing the page to be updated asynchronously.<\/p>\n<h2>The DOM<\/h2>\n<\/p>\n<p>The browser processes, or parses the information, transforming the tags, attributes, content, etc., into nodes that form a tree according to the document object model, the DOM. See the <a href=\"01-writing-html\/#dom\">demonstration<\/a>.\n<\/p>\n<p style=\"width: 486; margin: 0 auto;\"><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/htmlTree.gif\" alt=\"HTML DOM tree\"\/>\n<\/p>\n<p>The browser attempts to heal any errors that come up as the document tree is constructed. Each browser does that in their own way, meaning that the tree structure of the document can be different from one browser to the next. Part of the HTML5 specification is to create a unified way for browsers to handle non-valid documents, making sure that all browsers create the same DOM for any given page.\n<\/p>\n<p>JavaScript manipulates the properties and the elements in the DOM as soon as the page is loaded, or afterwards, if triggered by the user. Slight variations in how the different browsers handle JavaScript create big problems, which may or may not be the same from browser to browser. You can imagine that it used to be a real pain to program JavaScript.\n<\/p>\n<p>This pain kept the more integrated Javascript implementations out of general usage,  mostly relegating it to simple code snippets for much of its existence. The solution came with the development of cross browser JavaScript Libraries, which provide a simplified unified interface, or framework for implementing Javascript across the various browsers.\n<\/p>\n<p>There are well over 50 of such open source libraries, of which jQuery is but one. They all simplify the task of creating highly responsive web pages, abstracting away browser specific features that let designers concentrate on design and user interactivity.\n<\/p>\n<p>Then again, jQuery has won the hearts and minds of the web development community and has become ubiquitous since its release. It is the \u201cwrite less, do more\u201d library we all know and love.\n<\/p>\n<p>The browsers have cleaned up their act and support a uniform DOM implementation, these days. While this alone does not make jQuery superfluous, it is possible to make the case to write <a href=\"http:\/\/www.sitepoint.com\/jquery-vs-raw-javascript-1-dom-forms\/?utm_medium=email&#038;utm_campaign=SitePoint+Newsletter+June+13+2013&#038;utm_content=SitePoint+Newsletter+June+13+2013+CID_9617e0441b162d4e5e4e995d8c342299&#038;utm_source=Newsletter&#038;utm_term=Native%20JavaScript%20Equivalents%20of%20jQuery%20Methods\" >Javascript<\/a> instead of jQuery. If you wish to learn Javascript, you can read <a href=\"http:\/\/eloquentjavascript.net\">Eloquent Javascript<\/a> (<a href=\"http:\/\/eloquentjavascript.net\/Eloquent_JavaScript.pdf\">pdf<\/a>) for free on the web. <\/p>\n<h2>jQuery<\/h2>\n<\/p>\n<p>jQuery is one of the many JavaScript libraries created to ease JavaScript development.  <a href=\"http:\/\/ejohn.org\/\">John Resig<\/a>, the person who created the library, originally wanted to call it jSelect but the url was already taken, so it became jQuery. One of the most important things that jQuery does is provide a more uniform and easier to access ability to select DOM elements, removing the problems caused by different Javascript implementations and DOM error resolution.\n<\/p>\n<p>jQuery is very flexible when it comes to <a href=\"http:\/\/api.jquery.com\/category\/selectors\/\">selecting<\/a> DOM elements with the jQuery function, and it works similar to the way selectors do in CSS.\n<\/p>\n<p>In the same way that jQuery simplifies selecting DOM elements, it also makes manipulating the node objects much easier. It does not just return the DOM object but wraps each one of them with standard functions that make it really easy to manipulate them. You can show, toggle, hide, animate and <a href=\"http:\/\/api.jquery.com\/\">otherwise<\/a> manipulate and attach events to these objects with ease. <\/p>\n<h2>The Focus of jQuery<\/h2>\n<\/p>\n<p>From a <a href=\"http:\/\/ejohn.org\/apps\/workshop\/intro\/\">slideshow<\/a> by John Resig:\n<\/p>\n<p>In a nutshell:<\/p>\n<ul>\n<li>$(&#8220;div&#8221;).addClass(&#8220;special&#8221;);\n<\/li>\n<li>Find some elements \u2014 Better CSS Selector support than most browsers!\n<\/li>\n<li>Now that we&#8217;ve found the elements, let&#8217;s change them!\n<ul>\n<li><a href=\"http:\/\/docs.jquery.com\/Attributes\">Attributes<\/a> (addClass, attr)<\/li>\n<li><a href=\"http:\/\/docs.jquery.com\/CSS\">CSS<\/a> (css)<\/li>\n<li><a href=\"http:\/\/docs.jquery.com\/Manipulation\">Manipulation<\/a> (append, prepend, remove, clone)<\/li>\n<li><a href=\"http:\/\/docs.jquery.com\/Events\">Events<\/a> (click, hover, toggle)<\/li>\n<li><a href=\"http:\/\/docs.jquery.com\/Effects\">Effects<\/a> (hide, show, slideDown, fadeOut)<\/li>\n<li><a href=\"http:\/\/docs.jquery.com\/Ajax\">Ajax<\/a> (load, get, post)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>jQuery is Magic<\/h2>\n<\/p>\n<p>Many of jQueries perceived magic happens for designers, since many of its <a href=\"http:\/\/api.jquery.com\/category\/effects\/\">effects<\/a> are visual whenever it manipulates the document&#8217;s HTML or <a href=\"http:\/\/api.jquery.com\/category\/css\/\">CSS<\/a>, which it often does. It&#8217;s also magic in the way it simplifies <a href=\"http:\/\/api.jquery.com\/category\/ajax\/\">AJAX<\/a> and the <a href=\"http:\/\/api.jquery.com\/category\/utilities\/\">utilities<\/a> jquery has are really useful but that takes us well beyond the scope of this lecture. Since it&#8217;s best to learn jQuery&#8217;s visual effects through examples, lets do that. I will use the following <a href=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12_Basic_jQuery_Tutorial.zip\">files<\/a> in this basic <a href=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12_jQuery_Tutorial.html\">tutorial<\/a>.<\/p>\n<h2>Connect to the jQuery Library<\/h2>\n<\/p>\n<p>jQuery is a collection of javascript routines stored in a library. You access those routines when using jQuery. You can host this library yourself but its more usual to let Google host it for you.\n<\/p>\n<p>Download the <a href=\"http:\/\/code.jquery.com\/jquery.min.js\">compressed jQuery library<\/a> to use on your site. It is one big jumble of words and symbols with everything not necessary for its execution having been removed. You can take a look at the <a href=\"http:\/\/code.jquery.com\/jquery-1.7.js\">uncompressed jQuery library<\/a> if you like but unless you know Javascript, it will not make sense.\n<\/p>\n<p>Save the compressed jQuery library in your &#8220;js&#8221; script folder with the name &#8220;jquery.min.js&#8221; and link to it:<\/p>\n<pre>\r\n&lt;script src=\"js\/jquery.min.js\" type=\"text\/javascript\">\r\n<\/pre>\n<\/p>\n<p>Or link to it using Google:<\/p>\n<pre>\r\n&lt;script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\" type=\"text\/javascript\">\r\n<\/pre>\n<h2>Where to Put the Code<\/h2>\n<\/p>\n<p>Both JavaScript and jQuery need to be between <code>&lt;script>&lt;\/script><\/code> tags. Though these tags can be placed anywhere in the document, jQuery scripts are usually put in the head of the document using a function that takes care of the issue in Javascript where the code can run before the web page has been loaded, because it looks at the DOM.\n<\/p>\n<p>Javascript code, on the other hand, is usually placed at the bottom of the document, so that the scripts runs after all the elements in the body have loaded.\n<\/p>\n<p>If the scripts are used by other web pages on the site, it is common to create an external <code>script.js<\/code> file, in the same way that you would create a central external <code>style.css<\/code> file. <\/p>\n<pre>\r\n&lt;script type='text\/javascript' src=js\/scripts.js>&lt;\/script>\r\n<\/pre>\n<\/p>\n<p> In the head of the document a standard script tags links to the jQuery library served by Google: <\/p>\n<pre>\r\n&lt;script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\" type=\"text\/javascript\">&lt;\/script>\r\n<\/pre>\n<\/p>\n<p>This works when your document is on the server but not if you are developing your files locally on your hard disk. In that case, you need to include &#8220;http:&#8221; in front of the href address that Google left out. It should work fine after that.  <\/p>\n<pre>\r\n&lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\" type=\"text\/javascript\">&lt;\/script>\r\n<\/pre>\n<\/p>\n<p>Why does Google leave &#8220;http:&#8221; out? That way the script will work for both http and https (http secure) sites but just know that this doesn&#8217;t work when you are developing on your desktop.\n<\/p>\n<p>You can also download a copy of the &#8220;<a href=\"http:\/\/code.jquery.com\/jquery.min.js\">jquery.min.js<\/a>&#8221; file and link to that.\n<\/p>\n<p>Once you have connected to, or downloaded the jQuery library, you set up the open and closing <code>script<\/code> tags in which to embed the code: <\/p>\n<pre>\r\n&lt;script type=\"text\/javascript\">\r\n\r\n&lt;\/script>\r\n<\/pre>\n<h2>The Ready Event<\/h2>\n<\/p>\n<p>Next comes the initialization function called the ready event which waits for the document to be ready before it executes the jQuery code. This does not mean that the document and all the linked elements are fully downloaded but only that the DOM is finished, which the browser creates before it starts to parse the web page. <\/p>\n<pre>\r\n&lt;script type=\"text\/javascript\">\r\n\t$(document).ready(function() {\r\n\r\n\t});\r\n&lt;\/script>\r\n<\/pre>\n<\/p>\n<p>The ready event starts with the dollar sign <code>$<\/code> which stands for the jQuery object. If you want, you can replace the &#8220;$&#8221; with &#8220;jQuery&#8221; as I do in button #3 below. They are synonymous. This is where all of jQuery&#8217;s functionality is accessed from.\n<\/p>\n<p>The jQuery object is passed a function that says, &#8220;when the document (DOM hierarchy) is loaded and ready to be manipulated, then fire off this function.&#8221; The ready event keeps jQuery from prematurely executing before the page DOM has loaded. <\/p>\n<h2>The Event<\/h2>\n<\/p>\n<p>The jQuery library does not do anything by itself, it just enables us to do all kinds of stuff. From a designers perspective, it&#8217;s a way to capture events from the page, and then to do something, usually with CSS, like assign classes, removing classes, adding CSS to an object, or animating the CSS.\n<\/p>\n<p>CSS does this in a limited way all by itself. The link element animates when we hover the mouse over it.  You can use the hover event in jQuery but you can also use many other kinds of events. It&#8217;s able to capture that click or double click and do things other than open a link, as there are over <a href=\"http:\/\/api.jquery.com\/category\/events\/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DEvents%26redirect%3Dno\">40 events<\/a> that it can watch out for. That&#8217;s what makes it exciting.\n<\/p>\n<p>For example, Inside the ready event, a click handler is added:<\/p>\n<pre>\r\n&lt;script type=\"text\/javascript\">\r\n\t$(document).ready(function() {\r\n\t\t$(\".jq-1\").click(function() {\r\n\t});\r\n&lt;\/script>\r\n<\/pre>\n<\/p>\n<p>The click handler selects the object that, when clicked, executes whatever is in its brackets. In this case, it is the <a href=\"http:\/\/docs.jquery.com\/Effects\">effect<\/a> toggle, which toggles the CSS display value.<\/p>\n<pre>\r\n&lt;script type=\"text\/javascript\">\r\n\t$(document).ready(function() {\r\n\t\t$(\".jq-1\").click(function() {\r\n\t\t$(\"p\").toggle();\r\n\t\t});\r\n\t});\r\n&lt;\/script>\r\n<\/pre>\n<h2>Tutorial<\/h2>\n<\/p>\n<p>The <a href=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12_Basic_jQuery_Tutorial.zip\">files<\/a> for this basic <a href=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12_jQuery_Tutorial.html\">tutorial<\/a>.\n<\/p>\n<p>You will want to put the following code into the header:<\/p>\n<pre>\r\n&lt;style type=\"text\/css\"> \r\nsection {width: 800px; margin: 0 auto; background: hsla(50,100%,50%,.5); padding: 40px; position: relative; left: 0;}\r\n&lt;\/style>\r\n&lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\" type=\"text\/javascript\">&lt;\/script>\r\n&lt;script type=\"text\/javascript\">\r\n$(document).ready(function() {\r\n\t$(\"li.one\").click(function(){\r\n\t\t$(\"h1\").toggle();\r\n\t}); \r\n\t$(\"li.two\").click(function(){\r\n\t\t$(\"article\").slideToggle({\r\n\t\t});\r\n\t});  \r\n});\r\n&lt;\/script>\r\n<\/pre>\n<\/p>\n<p>And in the body, have the following code:<\/p>\n<pre>\r\n\t&lt;section>\r\n\t&lt;header>\r\n\t&lt;h1>jQuery Tutorial&lt;\/h1>\r\n\t\t&lt;nav>\r\n\t\t\t&lt;ul>\r\n\t\t\t\t&lt;li class=\"one\">&lt;a href=\"#\">Toggle Header&lt;\/a>&lt;\/li>\r\n\t\t\t\t&lt;li class=\"two\">&lt;a href=\"#\">Slide Body Copy&lt;\/a>&lt;\/li>\r\n\t\t\t&lt;\/ul>\r\n\t\t&lt;\/nav>\r\n\t&lt;\/header>\r\n\t&lt;article>\r\n\t\t&lt;p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \t\t&lt;\/p>\r\n\t\t&lt;p style=\"display:none\">Except the code itself.\r\n\t\t&lt;\/p>\r\n\t&lt;\/article>\r\n\t&lt;footer>&lt;\/footer>\r\n&lt;\/section>\r\n<\/pre>\n<h2>Functions<\/h2>\n<\/p>\n<p>Functions are a way of reusing code. Much like the external style sheets are all referenced by the different pages. Functions can be called any number of times rather than having to repeat all of that code every time. Writing functions is easy:<\/p>\n<pre>\r\nfunction colorMe(){\r\n\t$(\"p\").css(\"color\",\"hsla(220,100%,50%,1)\");\r\n\t$(\"h2\").css(\"color\",\"hsla(20,100%,50%,1)\");\r\n}\r\n<\/pre>\n<\/p>\n<p>The empty parentheses signify to not pass it any parameters. We do not need to worry about that here. We need to call the function to use it, which we do as follows:<\/p>\n<pre>\r\n$(\"jq-1\").click(function() {\r\n\tcolorMe();\r\n});\r\n<\/pre>\n<h2>Four Buttons<\/h2>\n<\/p>\n<p>The jQuery code is ready and watching the buttons to catch a click. When that happens, the corresponding code is executed. You execute the code by clicking the button.\n<\/p>\n<p>By clicking the first button <code>class=\"jq-1\"<\/code>, all the paragraphs <code>&lt;p><\/code> will be toggled from <code>visibility: default;<\/code> to <code>visibility: hidden;<\/code> and vice versa, meaning that all paragraphs that are currently hidden will show.\n<\/p>\n<p>Clicking the second button <code>class=\"jq-2\"<\/code> toggles the site&#8217;s navigation, which is in a div with <code>id=\"static\"<\/code>.\n<\/p>\n<p>Clicking the third button <code>class=\"jq-3\"<\/code> will <code>hide this slow<\/code>, with <code>this<\/code> being the object being talked about in the click handler, which is the third button. It will not come back until the page is refreshed\n<\/p>\n<p>Clicking the forth button <code>class=\"jq-4\"<\/code> changes the CSS color value on a number of different elements. It does this by calling the function <code>colorMe<\/code> which contains the code that changes the CSS of the elements.<\/p>\n<style>\n.button a {\ntext-decoration: none;\n\tfont-family: Arial, Helvetica, sans-serif;\n\tfont-size: 18px;\n\tcolor: #a13a15;\n\tpadding: 10px 26px;\n\tbackground: -moz-linear-gradient(\n\t\ttop,\n\t\t#c3c9e0 0%,\n\t\t#dae5e8 50%,\n\t\t#5569a3);\n\tbackground: -webkit-gradient(\n\t\tlinear, left top, left bottom, \n\t\tfrom(#c3c9e0),\n\t\tcolor-stop(0.50, #dae5e8),\n\t\tto(#5569a3));\n\tborder-radius: 12px;\n\t-moz-border-radius: 12px;\n\t-webkit-border-radius: 12px;\n\tborder: 3px solid #778ba8;\n\t-moz-box-shadow:\n\t\t0px 5px 10px rgba(000,000,000,0.5),\n\t\tinset -1px -1px 7px rgba(29,18,184,1);\n\t-webkit-box-shadow:\n\t\t0px 5px 10px rgba(000,000,000,0.5),\n\t\tinset -1px -1px 7px rgba(29,18,184,1);\n\ttext-shadow:\n\t\t0px -1px 9px rgba(000,000,000,0.1),\n\t\t0px 1px 8px rgba(255,255,255,1);\n}\n.button a:hover {\n\tfont-family: Arial, Helvetica, sans-serif;\n\tfont-size: 18px;\n\tcolor: #e7ed97;\n\tpadding: 10px 26px;\n\tbackground: -moz-linear-gradient(\n\t\ttop,\n\t\t#6282f5 0%,\n\t\t#6a8ae8 50%,\n\t\t#0541e6);\n\tbackground: -webkit-gradient(\n\t\tlinear, left top, left bottom, \n\t\tfrom(#6282f5),\n\t\tcolor-stop(0.50, #6a8ae8),\n\t\tto(#0541e6));\n\tborder-radius: 12px;\n\t-moz-border-radius: 12px;\n\t-webkit-border-radius: 12px;\n\tborder: 3px solid #778ba8;\n\t-moz-box-shadow:\n\t\t0px 5px 10px rgba(000,000,000,0.5),\n\t\tinset -1px -1px 7px rgba(029,018,184,1);\n\t-webkit-box-shadow:\n\t\t0px 5px 10px rgba(000,000,000,0.5),\n\t\tinset -1px -1px 7px rgba(029,018,184,1);\n\ttext-shadow:\n\t\t0px -1px 9px rgba(000,000,000,0.1),\n\t\t0px 1px 8px rgba(255,255,255,1);\n}\n<\/style>\n<p>Test it out:<a name=\"jq-demo\">&nbsp;<\/a><\/p>\n<pre>\r\n&lt;script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.0\/jquery.min.js\" type=\"text\/javascript\">&lt;\/script>\r\n&lt;script type=\"text\/javascript\">\r\nfunction colorMe(){\r\n\t$(\"p\").css(\"color\",\"hsla(220,100%,50%,1)\");\r\n\t$(\"h2\").css(\"color\",\"hsla(20,100%,50%,1)\");\r\n\t$(\"pre\").css(\"color\",\"hsla(120,100%,50%,1)\");\r\n\t$(\"li\").css(\"color\",\"hsla(170,100%,50%,1)\");\r\n\t$(\"h1\").css(\"color\",\"hsla(270,100%,50%,1)\");\r\n\t$(\"h3\").css(\"color\",\"hsla(320,100%,50%,1)\");\r\n\t$(\"#site-description\").css(\"color\",\"hsla(320,100%,50%,1)\");\r\n}\r\n$(document).ready(function() {\r\n\t$(\".jq-1\").click(function() {\r\n\t\t$(\"p\").toggle();\r\n\t});\r\n\t$(\".jq-2\").click(function() {\r\n\t\t$(\"#static\").fadeToggle();\r\n\t});\r\n\tjQuery(\".jq-3\").click(function(){\r\n\t\t$(this).hide(\"slow\");\r\n\t });\r\n\t$(\".jq-4\").click(function() {\r\n\t\t\tcolorMe();\r\n\t});\r\n});\r\n&lt;\/script>\r\n<\/pre>\n<p><script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.0\/jquery.min.js\" type=\"text\/javascript\"><\/script><br \/>\n<script type=\"text\/javascript\">\nfunction colorMeBack(){\n\t$(\"h2\").css(\"color\",\"hsla(20,0%,5%,1)\");\n\t$(\"pre\").css(\"color\",\"hsla(120,0%,10%,1)\");\n\t$(\"li\").css(\"color\",\"hsla(170,0%,10%,1)\");\n\t$(\"p\").css(\"color\",\"hsla(220,0%,10%,1)\");\n\t$(\"h1\").css(\"color\",\"hsla(270,0%,10%,1)\");\n\t$(\"h3\").css(\"color\",\"hsla(320,0%,10%,1)\");\n\t$(\"#site-description\").css(\"color\",\"hsla(320,0%,0%,1)\");\n\t$(\"#site-title\").css(\"color\",\"hsla(320,0%,0%,1)\");\n}\nfunction colorMe(){\n\t$(\"p\").css(\"color\",\"hsla(220,100%,50%,1)\");\n\t$(\"h2\").css(\"color\",\"hsla(20,100%,50%,1)\");\n\t$(\"pre\").css(\"color\",\"hsla(120,100%,50%,1)\");\n\t$(\"li\").css(\"color\",\"hsla(170,100%,50%,1)\");\n\t$(\"h1\").css(\"color\",\"hsla(270,100%,50%,1)\");\n\t$(\"h3\").css(\"color\",\"hsla(320,100%,50%,1)\");\n\t$(\"#site-description\").css(\"color\",\"hsla(320,100%,50%,1)\");\n}\n$(document).ready(function() {\n\t$(\".jq-1\").click(function() {\n\t\t$(\"p\").toggle();\n\t});\n\t$(\".jq-2\").click(function() {\n\t\t$(\"#static\").fadeToggle();\n\t});\n\tjQuery(\".jq-3\").click(function(){\n\t\t$(this).hide(\"slow\");\n\t });\n\t$(\".jq-4\").click(function() {\n\t\t\tcolorMe();\n\t});\n\t$(\".jq-5\").click(function() {\n\t\t\tcolorMeBack();\n\t});\n});\n<\/script><\/p>\n<div class=\"button\" style=\"float: left; padding-right: 10px;\"><a class=\"jq-1\" href=\"#jq-demo\">Toggle P<\/a><\/div>\n<div class=\"button\" style=\"float: left; padding-right: 10px;\"><a class=\"jq-2\" href=\"#jq-demo\">Toggle Nav<\/a><\/div>\n<div class=\"button\" style=\"float: left; padding-right: 10px;\"><a class=\"jq-3\" href=\"#jq-demo\">Hide<\/a><\/div>\n<div class=\"button\" style=\"float: left; padding-right: 10px;\"><a class=\"jq-4\" href=\"#jq-demo\">Color Text<\/a><\/div>\n<\/p>\n<p style=\"clear: both; display: none; color: red; font-size: 2em; padding-top: 30px; \">Oh oh, You just hid all of the paragraphs. Better click the button again.\n<\/p>\n<p style=\"display: none;\">Toggle P toggles between <code>display: default;<\/code> and  <code>display: none;<\/code>. The paragraphs that show up here, including this one and the one above were styled  <code>display: none;<\/code>. That is why they show up while the other disappear when you click the button. <\/p>\n<h2 style=\"display: none;\"> Javascript Performs on the DOM in the Browser&#8217;s Memory<\/h2>\n<\/p>\n<p style=\"display: none;\">If the letters in the headline are red, you clicked the Toggle P button without clicking on the Color Text button or its reset, blue if you clicked the Color Text button before toggling the paragraphs or black if you clicked the reset for the color Color Text button before clicking the first button.\n<\/p>\n<p style=\"display: none;\">This happens because Javascript does all of its work in the DOM hierarchy that the browser keeps in memory. The changes to the page are done only in memory. Whatever changes in value that jQuery makes on the DOM stay that way until the page is refreshed, in which case it requests the original values from the server and resets the DOM.\n<\/p>\n<p style=\"display: none;\">The point to take away from this is that the Browser keeps the entire web page including all of its resources in memory, and that is where Javascript&#8217;s changes take affect, changing the DOM, and thus, changing the way the page looks.\n<\/p>\n<p style=\"clear: both; padding-top: 30px; \">You can <a class=\"jq-5\" href=\"#jq-demo\">reset<\/a> the colors if you want. <\/p>\n<h2>Rethinking Website Design <\/h2>\n<\/p>\n<p> Major design decisions can be based on interactive code, like what happens when the code is executed on this page when clicking the buttons above.\n<\/p>\n<p> jQuery is a powerful way to manipulate your CSS and HTML. From a designers&#8217;s point of view, it&#8217;s an extension of HTML and CSS, an amazing expansion of what&#8217;s possible over using just HTML and CSS alone.\n<\/p>\n<p>This introduction gives you a taste of what&#8217;s possible. It will take some time to redesign your web pages once you have the power of Javascript as harnessed by jQuery under your belt. My guess is that you&#8217;ll be egging yourself on to learn jQuery after this course has finished. Linda.com has good tutorials that will help you find your way.<\/p>\n<h2>Examples<\/h2>\n<\/p>\n<p>Javascript and jQuery scripts can often by copied, and with a few tweaks, used to add behavior to your website. The follow examples give you a place to start.\n<\/p>\n<p>Simple Javascript <a href=\"http:\/\/www.javascriptkit.com\/script\/script2\/randomslide.shtml\"> Random Image Slideshow<\/a>. Copy the script, paste it between the body tag, replace the images and set the delay, to something other than 1 second.\n<\/p>\n<p>JQuery develops a number of <a href=\"http:\/\/jQueryui.com\/demos\/\">demos<\/a> and a link to a complete <a href=\"http:\/\/css-tricks.com\/examples\/AnythingSlider\/\">jQuery Image Slider<\/a>. Be forwarded. There are many default options and you will have to change the parameters to make it look good. The benefit is that this slider is fully documented.\n<\/p>\n<p>Parallax scrolling is all the rage. This means that a number of elements scroll past at different speeds. The Nike website made this famous, and here is a <a href=\"http:\/\/coding.smashingmagazine.com\/2011\/07\/12\/behind-the-scenes-of-nike-better-world\/\">tutorial<\/a> of how to accomplish that. It is a great tutorial on <a href=\"https:\/\/github.com\/richardshepherd\/Parallax-Scrolling\">GitHub<\/a>with <a href=\"https:\/\/github.com\/richardshepherd\/Parallax-Scrolling\/archive\/master.zip\">source code<\/a>.\n<\/p>\n<p>If you find code you like but someone has compressed their Javascript into an unreadable form, you can use<a href=\"http:\/\/jsbeautifier.org\/\"> beautifier<\/a> to made the code readable.<\/p>\n<h2>Smooth Scrolling Animation<\/h2>\n<\/p>\n<p>Most people are attracted seeing their webpages scroll to a location on the page, which has led to a revolution in single page designs rather than multipage designs. A very simple solution is <a href=\"http:\/\/arbitrary-anchor.briangonzalez.org\">arbitrary anchor<\/a>.\n<\/p>\n<p>A much fancier <a href=\"http:\/\/tympanus.net\/Freebies\/Boxify\/\">single page website template<\/a> is created by <a href=\"http:\/\/peterfinlan.com\">Peter Finlan<\/a>. Another flavor is <a href=\"http:\/\/tympanus.net\/codrops\/2016\/04\/29\/freebie-synthetica-one-page-website-template\/\">synthethica<a><\/a>. While it is tempting to use these ready made templates as a starting point, try to understand how jQuery (and the many other technologies) are implemented so you can do something on your own instead. <\/p>\n<h2>Simple jQuery Slider<\/h2>\n<p>Everyone asks for an image slider. This one is simple. <a href=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-Gallery.zip\">Download demo<\/a><\/p>\n<h3>Add CSS styles<\/h3>\n<pre>\r\n#gallery {width: 601px; margin: 0 auto;}\r\n#gallery li {display: inline; margin-right: 3px;}\r\n<\/pre>\n<h3> Add link to jQuery<\/h3>\n<pre>\r\n&lt;script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\" type=\"text\/javascript\">&lt;\/script>\r\n<\/pre>\n<\/p>\n<p>or if on the desktop: <\/p>\n<pre>\r\n&lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\" type=\"text\/javascript\">&lt;\/script>\r\n<\/pre>\n<h3>Add jQuery Code <\/h3>\n<pre>\r\n$(document).ready(function() {\r\n\t$(\"#gallery li img\").hover(function(){\r\n\t\t$('#main-img').attr('src',$(this).attr('src').replace('thumb\/', ''));\r\n\t});\r\n\tvar imgSwap = [];\r\n\t $(\"#gallery li img\").each(function(){\r\n\t\timgUrl = this.src.replace('thumb\/', '');\r\n\t\timgSwap.push(imgUrl);\r\n\t});\r\n\t$(imgSwap).preload();\r\n});\r\n$.fn.preload = function() {\r\n    this.each(function(){\r\n        $('<img \/>')[0].src = this;\r\n    });\r\n}\r\n<\/pre>\n<h3>Add HTML<\/h3>\n<pre style=\"font-size: 80%;\">\r\n\t&lt;div id=\"gallery\">\r\n\t&lt;img src=\"gallery\/img_1.jpg\" alt=\"\" id=\"main-img\" \/>\r\n\t&lt;ul>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_1.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_2.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_3.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_4.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_5.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_6.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_7.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_8.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_9.jpg\" alt=\"\" \/>\r\n\t  &lt;li>&lt;img src=\"gallery\/thumb\/img_10.jpg\" alt=\"\" \/>\r\n\t\r\n&lt;\/div>\r\n<\/pre>\n<style>\n#gallery {width: 45vw; margin: 0 auto;}\n#gallery ul {display: flex; list-style: none; justify-content: space-between; flex-wrap: wrap; }\n#main-img {width: 45vw;}\n#gallery ul img {width: 3.9vw;}\n<\/style>\n<p><script type=\"text\/JavaScript\">\n\/\/ prepare the form when the DOM is ready \n$(document).ready(function() {\n\t$(\"#gallery li img\").hover(function(){\n\t\t$('#main-img').attr('src',$(this).attr('src').replace('thumb\/', ''));\n\t});\n\tvar imgSwap = [];\n\t $(\"#gallery li img\").each(function(){\n\t\timgUrl = this.src.replace('thumb\/', '');\n\t\timgSwap.push(imgUrl);\n\t});\n\t$(imgSwap).preload();\n});\n$.fn.preload = function() {\n    this.each(function(){\n        $('<img \/>')[0].src = this;\n    });\n}\n<\/script><\/p>\n<div id=\"gallery\" style=\"width: 100%\">\n\t<img decoding=\"async\" style=\"width: 100%;\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/img_1.jpg\" alt=\"\" id=\"main-img\" \/><\/p>\n<ul>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_1.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_2.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_3.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_4.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_5.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_6.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_7.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_8.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_9.jpg\" alt=\"\" \/>\n\t  <\/li>\n<li><img decoding=\"async\" src=\"http:\/\/b.parsons.edu\/~dejongo\/12-fall\/stuff\/12-gallery\/thumb\/img_10.jpg\" alt=\"\" \/>\n\t<\/li>\n<\/ul>\n<\/div>\n<h2>Javascript is Back<\/h2>\n<\/p>\n<p> Now that the browsers have cleaned up their act, it is possible to skip the need for jQuery and do everything in Javascript. You can try the <a href=\"http:\/\/pedroduarte.me\/wallop-slider\/\">Wallop Slider<\/a>. The instructions for a slider are a little more complex but it does not use the jQuery library.\n<\/p>\n<p>The next frontier would be to develop your web site interactivity using Javascript and jQuery but it is more important that you create good websites first. Javascript requires that the website you build is well designed. That is the focus of this class, so there is no Javascript or jQuery requirement for the final.\n<\/p>\n<p>Want to know more about javascript? Try the <a href=\"https:\/\/wesbos.com\/beginner-javascript\">WesBos Javascript for Designers<\/a> and make sure you get the student discount. Here is  beginner\u2019s <a href=\"https:\/\/websitesetup.org\/javascript-cheat-sheet\/\">Essential Javascript Cheat Sheet<\/a>  and <a href=\"https:\/\/websitesetup.org\/wp-content\/uploads\/2020\/09\/Javascript-Cheat-Sheet.pdf\">PDF version<\/a> for those who know just enough JavaScript to get them into trouble.\n<\/p>\n<p>If you want to learn more about jQuery?, <a href=\"https:\/\/learn.jquery.com\/about-jquery\/how-jquery-works\/\">do so<a><\/a> but you are on your own. There are advanced courses that address programming. You can also look up videos on Linda.com or explore the web.<\/p>\n<p>That should not stop anyone, however, from trying it out, once you have developed some solid HTML and CSS skills, and have a working website. So here are some code snippet that can help you create well designed web sites, as  Aditi Timbadia <a href=\"http:\/\/b.parsons.edu\/~timba433\/parsons\/finalproject\/landingpg.html\">demonstrates<\/a> (she implements side navigation).<\/p>\n<h2> Useful Javascript Snippets from W3schools<\/h2>\n<h4><a href=\"https:\/\/www.w3schools.com\/howto\/default.asp\">HOW TO<\/a><\/h4>\n<\/p>\n<p>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_tabs.asp\">Tabs<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_css_dropdown.asp\">Dropdowns<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_accordion.asp\">Accordions<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_hover_tabs.asp\">Hover tabs<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_weight_converter.asp\">Convert Weights<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_css_animate_buttons.asp\">Animated Buttons<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_sidenav.asp\">Side Navigation<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_topnav.asp\">Top Navigation<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_navbar_hide_scroll.asp\">Navbar hides when scrolling<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_navbar_shrink_scroll.asp\">Navbar shrinks when scrolling<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_navbar_sticky.asp\">Sticky Navbar<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_mobile_navbar.asp\">Mobile Navbar<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_css_parallax.asp\">Parallax<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_html_include.asp\">HTML Includes<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_google_maps.asp\">Google Maps<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_css_tooltip.asp\">Tooltips<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_slideshow.asp\">Slideshow<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_filter_lists.asp\">Filter List<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/howto\/howto_js_sort_list.asp\">Sort List<\/a>\n<\/p>\n<p><\/a><\/p>\n<p><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If HTML is for content and CSS for presentation, than Javascript is for behavior. It really takes mastery of all three to become a web designer. It is, unfortunately, too much for this coures to tackle all three, so we &hellip; <a href=\"https:\/\/b.parsons.edu\/~dejongo\/12-javascriptjquery\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/752"}],"collection":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/comments?post=752"}],"version-history":[{"count":68,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/752\/revisions"}],"predecessor-version":[{"id":5074,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/752\/revisions\/5074"}],"wp:attachment":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/media?parent=752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/categories?post=752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/tags?post=752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}