{"id":1824,"date":"2018-04-07T13:59:54","date_gmt":"2018-04-07T18:59:54","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=1824"},"modified":"2018-04-25T20:56:38","modified_gmt":"2018-04-26T01:56:38","slug":"jquery-use-jquery-project-confirm-working","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2018\/04\/07\/jquery-use-jquery-project-confirm-working\/","title":{"rendered":"jQuery: How to use jQuery in a project and confirm it is working"},"content":{"rendered":"<p>The fastest way to make jQuery available for a project is to use a CDN in the HEAD portion of the HTML. For example, here is a CDN for jQuery 3.3.1:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.3.1\/jquery.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>With this in place, you can confirm that jQuery is available and working by adding this block of JavaScript code to the script portion of the HTML:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">  window.onload = function() {\r\n    if (window.jQuery) {\r\n        \/\/ jQuery is loaded\r\n        alert(\"jQuery is working!\");\r\n    } else {\r\n        \/\/ jQuery is not loaded\r\n        alert(\"Hmm, jQuery not working.\");\r\n    }\r\n  }<\/pre>\n<p>If jQuery is running, the alert will say &#8220;jQuery is working!&#8221;. Otherwise the alert will say &#8220;Hmm, jQuery not working.&#8221;. You can test this by commenting and uncommenting the jQuery CDN.<\/p>\n<p>Another way to use jQuery is to download the package and call it locally rather than use a CDN. For example, on this download page:<br \/>\n<a href=\"http:\/\/jquery.com\/download\/\">http:\/\/jquery.com\/download\/<\/a><\/p>\n<p>I chose the option &#8220;Download the compressed, production jQuery 3.3.1&#8221;:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1829\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/download-jquery.png\" alt=\"\" width=\"1002\" height=\"373\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/download-jquery.png 1002w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/download-jquery-300x112.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/download-jquery-768x286.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/download-jquery-676x252.png 676w\" sizes=\"auto, (max-width: 1002px) 100vw, 1002px\" \/><\/p>\n<p>Which sent me to this page:<br \/>\n<a href=\"https:\/\/code.jquery.com\/jquery-3.3.1.min.js\">https:\/\/code.jquery.com\/jquery-3.3.1.min.js<\/a><\/p>\n<p>To save the code, right click and choose &#8220;Save Page As&#8230;&#8221;:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1830\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/jquery-save-as.png\" alt=\"\" width=\"484\" height=\"464\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/jquery-save-as.png 484w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/jquery-save-as-300x288.png 300w\" sizes=\"auto, (max-width: 484px) 100vw, 484px\" \/><\/p>\n<p>Save this to the directory your project is in, and then call it in the HTML like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;script src=\"jquery-3.3.1.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>Then test to make sure it is working the same way described above.<\/p>\n<p>Here is what w3schools says about jQuery:<\/p>\n<blockquote><p>jQuery is a lightweight, &#8220;write less, do more&#8221;, JavaScript library.<\/p>\n<p>The purpose of jQuery is to make it much easier to use JavaScript on your website.<\/p>\n<p>jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.<\/p>\n<p>jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.<\/p>\n<p>The jQuery library contains the following features:<\/p>\n<ul>\n<li>HTML\/DOM manipulation<\/li>\n<li>CSS manipulation<\/li>\n<li>HTML event methods<\/li>\n<li>Effects and animations<\/li>\n<li>AJAX<\/li>\n<li>Utilities<\/li>\n<\/ul>\n<p>In addition, jQuery has plugins for almost any task out there.<\/p><\/blockquote>\n<p>For more information about getting started with jQuery, see:<br \/>\n<a href=\"https:\/\/www.w3schools.com\/jquery\/jquery_get_started.asp\">https:\/\/www.w3schools.com\/jquery\/jquery_get_started.asp<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The fastest way to make jQuery available for a project is to use a CDN in the HEAD portion of the HTML. For example, here is a CDN for jQuery 3.3.1: &lt;script src=&#8221;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.3.1\/jquery.min.js&#8221;&gt;&lt;\/script&gt; With this in place, you can confirm that jQuery is available and working by adding this block of JavaScript code to the &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2018\/04\/07\/jquery-use-jquery-project-confirm-working\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">jQuery: How to use jQuery in a project and confirm it is working<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,128],"tags":[45,123],"class_list":["post-1824","post","type-post","status-publish","format-standard","hentry","category-javascript-language","category-jquery","tag-javascript","tag-jquery"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=1824"}],"version-history":[{"count":6,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1824\/revisions"}],"predecessor-version":[{"id":1834,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1824\/revisions\/1834"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=1824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=1824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=1824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}