Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.47 KB | None | 0 0
  1. //jQuery learning
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <title>Getting started with jQuery</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. color: rgb(16, 10, 102);
  11. }
  12. </style>
  13. </head>
  14. <body>
  15.  
  16. <h1 id="heading">What is jQuery?</h1>
  17.  
  18. <p>jQuery is the most popular JavaScript library. It gives developers lots of useful functions so they can make their webpage interactive across multiple browsers.</p>
  19.  
  20. <p class="note">jQuery is an open source library with a big community of contributors.</p>
  21.  
  22. <h1>Why should you learn jQuery?</h1>
  23.  
  24. <p>If you learn jQuery, you'll be able to use it in your own webpages, understood other developer's webpages, and have a better understanding generally about how to use libraries.</p>
  25.  
  26. <p class="note">Note: jQuery functions use the DOM API (like <code>document.getElementById</code>). You should learn that first, if you haven't yet.</p>
  27. <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
  28. </script>
  29.  
  30. <script>
  31. $("h1").text("jQuery string");
  32. </script>
  33.  
  34. </body>
  35. </html>
  36.  
  37.  
  38.  
  39.  
  40. <!DOCTYPE html>
  41. <html>
  42. <head>
  43. <meta charset="utf-8">
  44. <title>Challenge: Your first jQuery</title>
  45. </head>
  46. <body>
  47.  
  48. <h1>Just a normal webpage...</h1>
  49.  
  50. <h1>until...</h1>
  51.  
  52. <h1>you include jQuery!</h1>
  53. <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
  54.  
  55. </script>
  56.  
  57. <script>$("h1").text("jQuery");</script>
  58. </body>
  59. </html>
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. <!DOCTYPE html>
  69. <html>
  70. <head>
  71. <meta charset="utf-8">
  72. <title>Finding elements with jQuery</title>
  73. <style>
  74. body {
  75. font-family: Arial, sans-serif;
  76. color: rgb(16, 10, 102);
  77. }
  78. p
  79. {
  80. color: red;
  81. }
  82. #main-heading
  83. {
  84. color: purple;
  85. }
  86. .note
  87. {
  88. background: yellow;
  89. }
  90. </style>
  91. </head>
  92. <body>
  93.  
  94. <h1 id="main-heading">What is jQuery?</h1>
  95.  
  96. <p>jQuery is the most popular JavaScript library. It gives developers lots of useful functions so they can make their webpage interactive across multiple browsers.</p>
  97.  
  98. <p class="note">jQuery is an open source library with a big community of contributors.</p>
  99.  
  100. <h1>Why should you learn jQuery?</h1>
  101.  
  102. <p>If you learn jQuery, you'll be able to use it in your own webpages, understand other developer's webpages, and have a better understanding generally about how to use libraries.</p>
  103.  
  104. <p class="note">Note: jQuery functions use the DOM API (like <code>document.getElementById</code>). You should learn that first, if you haven't yet.</p>
  105.  
  106. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  107.  
  108. <script>
  109. $("p").text("jQuery is the GREATEST!!!");
  110. $("#main-heading").text("a jQuery string");
  111. $(".note").text("another string obviously");
  112. </script>
  113. </body>
  114. </html>
  115.  
  116.  
  117.  
  118. <!DOCTYPE html>
  119. <html>
  120. <head>
  121. <meta charset="utf-8">
  122. <title>Challenge: Unicorn-ify a page with jQuery</title>
  123. </head>
  124. <body>
  125.  
  126. <h1 id="page-heading">All About Horses</h1>
  127.  
  128. <p>All <span class="animal">horses</span> gallop on 4 legs.</p>
  129.  
  130. <p>You can feed carrots to <span class="animal">horses</span>.</p>
  131.  
  132. <p>Never walk behind <span class="animal">horses</span>.</p>
  133.  
  134. <p>Their most notable body parts:</p>
  135. <ul>
  136. <li>Strong legs</li>
  137. <li>Long mane</li>
  138. <li>Hooved feet</li>
  139. </ul>
  140.  
  141. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  142. <script>
  143. $("li").text("horn");
  144. $("#page-heading").text("All about unicorns");
  145. $(".animal").text("unicorns");
  146. $("p").text("unicorns");
  147.  
  148.  
  149. </script>
  150. </body>
  151. </html>
  152.  
  153.  
  154.  
  155.  
  156. <!DOCTYPE html>
  157. <html>
  158. <head>
  159. <meta charset="utf-8">
  160. <title>Getting info on elements with jQuery</title>
  161. <style>
  162. body {
  163. font-family: Arial, sans-serif;
  164. color: rgb(16, 10, 102);
  165. }
  166.  
  167. p {
  168. color: red;
  169. }
  170.  
  171. #main-heading {
  172. color: purple;
  173. }
  174.  
  175. .note {
  176. background: yellow;
  177. }
  178. </style>
  179. </head>
  180. <body>
  181.  
  182. <h1 id="main-heading">What is jQuery?</h1>
  183.  
  184. <p>jQuery is the most popular JavaScript library. It gives developers lots of useful functions so they can make their webpage interactive across multiple browsers.</p>
  185.  
  186. <p class="note">jQuery is an open source library with a big community of contributors.</p>
  187.  
  188. <h1>Why should you learn jQuery?</h1>
  189.  
  190. <p>If you learn jQuery, you'll be able to use it in your own webpages, understand other developer's webpages, and have a better understanding generally about how to use libraries.</p>
  191.  
  192. <p class="note">Note: jQuery functions use the DOM API (like <code>document.getElementById</code>). You should learn that first, if you haven't yet.</p>
  193.  
  194. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  195.  
  196. <script>
  197. $("p").text("jQuery is the GREATEST!!!");
  198. //$("#main-heading").text("jQuery? More like YAY-QUERY!");
  199. $(".note").text("NOTE: jQuery has been known to cause EXTREME JOY!");
  200.  
  201. var headingText = $("#main-heading").text();
  202. consloge.log(headingText);
  203. $("#main-heading").text("!!" + headingText + "a string");
  204. </script>
  205. </body>
  206. </html>
  207.  
  208.  
  209.  
  210.  
  211.  
  212. <!DOCTYPE html>
  213. <html>
  214. <head>
  215. <meta charset="utf-8">
  216. <title>Challenge: Famous discoveries</title>
  217. </head>
  218. <body>
  219.  
  220. <h1>Famous discoveries</h1>
  221.  
  222. <h2 id="math-heading">Math discoveries</h2>
  223.  
  224. <ul>
  225. <li>323–283 BC – Euclid: wrote a series of 13 books on geometry called The Elements</li>
  226. <li>Al-Khawarizmi (780-850): wrote the first major treatise on Algebra titled "Al-jabr wal-muqabaleh"</li>
  227. </ul>
  228.  
  229. <h2 id="science-heading">Science discoveries</h2>
  230. <ul>
  231. <li>1543 – Copernicus: discovered the heliocentric model of the solar system.
  232. </li>
  233. <li>1672 – Sir Isaac Newton: discovers that white light is a spectrum of a mixture of distinct coloured rays.</li>
  234. </ul>
  235.  
  236. <a href="https://en.wikipedia.org/wiki/Timeline_of_scientific_discoveries">Read about more discoveries on Wikipedia.</a>
  237.  
  238. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  239. <script>
  240. var math = $("#math-heading");
  241. var science = $("#science-heading");
  242. math.text(math.text() + " + a string");
  243. science.text(science.text() + " + a string");
  244.  
  245.  
  246. </script>
  247. </body>
  248. </html>
  249.  
  250.  
  251. <script>
  252. $("h1"); // selects all the h1s
  253. $("#heading"); // selects the element with id of "heading"
  254. $(".warning"); // selects all the elements with class name of "warning"
  255. jQuery("h1");
  256. jQuery("#heading");
  257. jQuery(".warning");
  258. var heading = $("#heading").text();
  259. </script>
  260.  
  261.  
  262. <!DOCTYPE html>
  263. <html>
  264. <head>
  265. <meta charset="utf-8">
  266. <title>jQuery example: text()</title>
  267. <style>
  268. .weather {
  269. background: rgb(179, 177, 179);
  270. margin-right: 447px;
  271. margin-left: 1px;
  272. padding-left: 3px;
  273. }
  274.  
  275. body {
  276. font-family: arial;
  277. }
  278. </style>
  279. </head>
  280. <body>
  281. <h1>Winston's Weather Report</h1>
  282. <img src="https://www.kasandbox.org/programming-images/creatures/Winston.png">
  283. <!-- The weather report always changes! --->
  284. <!-- This was the original weather... -->
  285. <h2 class="weather">Current Weather:</h2>
  286. <p class="weather" id="temperature">76° Fahrenheit</p>
  287.  
  288. <!-- adding jQuery -->
  289. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
  290. </script>
  291.  
  292. <script>
  293. // Let's use jQuery to change the weather
  294. // We do that by selecting the temperature paragraph with the "temperature" id and using .text() to change the text
  295. $("#temperature").text("89° Fahrenheit");
  296.  
  297. // Looks like it got hotter!
  298. </script>
  299. </body>
  300. </html>
  301. <!-- Example created by Akul Umamageswaran:
  302. https://www.khanacademy.org/profile/technologywiz/ -->
  303.  
  304.  
  305. <script>
  306. $("h1").text();
  307. $("h1").length;
  308. </script>
  309.  
  310.  
  311.  
  312.  
  313.  
  314. <!DOCTYPE html>
  315. <html>
  316. <head>
  317. <meta charset="utf-8">
  318. <title>Modifying elements with jQuery</title>
  319. <style>
  320. .gil
  321. {
  322. color: green;
  323. font-family: fantasy;
  324. }
  325. </style>
  326. </head>
  327. <body>
  328.  
  329. <h2 id="cuteness">Cats are cute</h2>
  330.  
  331. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  332.  
  333. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  334. <a href="https://en.wikipedia.org/wiki/Cat_food">
  335. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="200">
  336. </a>
  337.  
  338. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  339.  
  340. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  341. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="200">
  342.  
  343. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  344.  
  345. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  346. <script>
  347. $("h2").text("a string");
  348. $("p").html("another <strong>string </strong>");
  349. $("p").css("color", "green");
  350. $("h2").addClass("gil");
  351. $("a").attr("href", "https://en.wikipedia.org/");
  352. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  353.  
  354. </script>
  355. </body>
  356. </html>
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363. <!DOCTYPE html>
  364. <html>
  365. <head>
  366. <meta charset="utf-8">
  367. <title>Challenge: The changing caterpillar</title>
  368. </head>
  369. <body>
  370. <h1>The Caterpillar</h1>
  371.  
  372. <p>This is a <strong>caterpillar</strong> in its natural habitat:</p>
  373. <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f5/Monarch_caterpillar_on_swan_plant_branchlet.jpg/640px-Monarch_caterpillar_on_swan_plant_branchlet.jpg" width="400">
  374.  
  375.  
  376. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  377. <script>
  378. $("h1").text("butterflies");
  379. $("p").html("butterflies");
  380. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/butterfly_monarch.png");
  381. $("p").css("color", "orange");
  382. </script>
  383.  
  384. </body>
  385. </html>
  386.  
  387.  
  388.  
  389.  
  390. <!DOCTYPE html>
  391. <html>
  392. <head>
  393. <meta charset="utf-8">
  394. <title>Creating elements with jQuery</title>
  395. <style>
  396. .crocodile {
  397. color: green;
  398. font-family: fantasy;
  399. }
  400. </style>
  401. </head>
  402. <body>
  403.  
  404. <h2 id="cuteness">Cats are cute!</h2>
  405.  
  406. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  407.  
  408. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  409. <a href="https://en.wikipedia.org/wiki/Cat_food">
  410. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  411. </a>
  412.  
  413. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  414.  
  415. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  416. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  417.  
  418. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  419.  
  420. here
  421. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  422. <script>
  423. $("h2").text("CROCODILE ATTACK!");
  424. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  425. $("p").css("color", "green");
  426. $("h2").addClass("crocodile");
  427. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  428. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  429.  
  430. var newP = $("<p>");
  431. newP.text("a string");
  432. newP.addCLass("crocodile");
  433. $("body").append(newP);
  434.  
  435.  
  436. </script>
  437. </body>
  438. </html>
  439.  
  440.  
  441.  
  442.  
  443. <!DOCTYPE html>
  444. <html>
  445. <head>
  446. <meta charset="utf-8">
  447. <title>Challenge: Creature creator</title>
  448. <style>
  449. body {
  450. font-family: sans-serif;
  451. }
  452. .result {
  453. font-size: 20px;
  454. font-weight: bold;
  455. color: blue;
  456. }
  457. </style>
  458. </head>
  459. <body>
  460. <h1>Creature Creator</h1>
  461.  
  462. <p>What happens when you combine these two animals?</p>
  463. <img src="https://www.kasandbox.org/programming-images/animals/shark.png" height="150" alt="shark">
  464. <img src="https://www.kasandbox.org/programming-images/animals/spider.png" height="150" alt="spider">
  465.  
  466. <p class="result">You get a sharkspider!</p>
  467.  
  468. <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
  469. <script>
  470. var newP = $("<p>");
  471. newP.text("this is text");
  472. newP.addClass("result")
  473. $("body").append(newP);
  474.  
  475.  
  476. </script>
  477. </body>
  478. </html>
  479.  
  480. <script>
  481. $("h1").text("All about cats");
  482. $("h1").html("I <strong>love</strong> cats");
  483. $(".dog-pic").attr("src", "dog.jpg");
  484. $(".google-link").attr("href", "http://www.google.com");
  485. $("h1").css("font-family", "monospace");
  486. $("h1").css({"font-family": "monospace", color: "red"});
  487. $("h1").addClass("warning");
  488. var $p = $("<p>");
  489. var $p = $('<p style="color:red;">I love people who love cats.</p>');
  490. $p.addClass("warning");
  491. $("#main-div").append($p);
  492. </script>
  493.  
  494. <script>
  495. $("body").text("Mwahahaha");
  496. $("img").attr("src", "https://pbs.twimg.com/profile_images/616542814319415296/McCTpH_E.jpg");
  497. </script>
  498.  
  499.  
  500.  
  501.  
  502. <!DOCTYPE html>
  503. <html>
  504. <head>
  505. <meta charset="utf-8">
  506. <title>jQuery Collections vs. DOM Nodes</title>
  507. <style>
  508. .crocodile {
  509. color: green;
  510. font-family: fantasy;
  511. }
  512. </style>
  513. </head>
  514. <body>
  515.  
  516. <h2 id="cuteness">Cats are cute!</h2>
  517.  
  518. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  519.  
  520. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  521. <a href="https://en.wikipedia.org/wiki/Cat_food">
  522. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  523. </a>
  524.  
  525. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  526.  
  527. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  528. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  529.  
  530. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  531.  
  532. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  533. <script>
  534. // Modifying elements
  535. $("h2").text("CROCODILE ATTACK!");
  536. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  537. $("p").css("color", "green");
  538. $("h2").addClass("crocodile");
  539. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  540. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  541.  
  542. // Creating elements
  543. var newP = $("<p>");
  544. newP.text("The crocodiles have eaten this ENTIRE PAGE!");
  545. newP.addClass("crocodile");
  546. $("body").append(newP);
  547.  
  548. // Let's discuss:
  549. var headingFromD = document.getElementById("cuteness");
  550. // DOM node
  551. headingFromD.innerHTML = "Setting . innterHTML";
  552. var headingFromJ = $("#cuteness");
  553. headingFromJ.html("using .html()");
  554.  
  555. var $heading = $("cuteness");
  556. $heading.html("using jQuery");
  557. var headingD = $heading[0];
  558.  
  559. var $headingJ = $(headingD);
  560.  
  561. </script>
  562. </body>
  563. </html>
  564.  
  565.  
  566. heading.text("Best heading ever");
  567.  
  568.  
  569.  
  570. <!DOCTYPE html>
  571. <html>
  572. <head>
  573. <meta charset="utf-8">
  574. <title>Looping through jQuery collections</title>
  575. <style>
  576. .crocodile {
  577. color: green;
  578. font-family: fantasy;
  579. }
  580. </style>
  581. </head>
  582. <body>
  583.  
  584. <h2 id="cuteness">Cats are cute!</h2>
  585.  
  586. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  587.  
  588. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  589. <a href="https://en.wikipedia.org/wiki/Cat_food">
  590. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  591. </a>
  592.  
  593. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  594.  
  595. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  596. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  597.  
  598. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  599.  
  600. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  601. <script>
  602. // Modifying elements
  603. $("h2").text("CROCODILE ATTACK!");
  604. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  605.  
  606. var $paragraph = $('p');
  607. for (var i = 0; i < $paragraph.length; i +=1)
  608. {
  609. var element = $paragraph[i]; // DOM node
  610. var $paragraph = $(element);
  611. $paragraph.html(€paragraph.html() + "a string");
  612. }
  613.  
  614. $paragraph.each(function(index, element)
  615. {
  616. var $paragraph = $(element); //$(this);
  617. console.log(element === this);
  618. $paragraph.html( $paragraph.html() + "..wowee!");
  619. }
  620. );
  621.  
  622. $("p").css("color", "green");
  623. $("h2").addClass("crocodile");
  624. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  625. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  626.  
  627.  
  628. </script>
  629. </body>
  630. </html>
  631.  
  632.  
  633.  
  634.  
  635.  
  636. <!DOCTYPE html>
  637. <html>
  638. <head>
  639. <meta charset="utf-8">
  640. <title>Challenge: Loopy language</title>
  641. </head>
  642. <body>
  643.  
  644. <h1>All about Pig Latin</h1>
  645. <p>Pig Latin is a language game in which words in English are altered. The objective is to conceal the meaning of the words from others not familiar with the rules. The reference to Latin is a deliberate misnomer, as it is simply a form of jargon, used only for its English connotations as a strange and foreign-sounding language.</p>
  646. <p>The origins of Pig Latin are unknown. A youthful Thomas Jefferson wrote letters to friends in Pig Latin.</p>
  647. <p>For words that begin with consonant sounds, the initial consonant or consonant cluster is moved to the end of the word, and "ay" is added.</p>
  648.  
  649.  
  650. <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
  651. <script>
  652. // Takes a string and returns Pig Latin version of it
  653. var toPigLatin = function(str) {
  654. if (!str.replace) {
  655. return 'ERROR: Expected a string!';
  656. }
  657. return str.replace(/\b(\w)(\w+)\b/g, '$2-$1ay').toLowerCase();
  658. };
  659.  
  660. // Iterate through each paragraph, call the toPigLatin function on it
  661. var $paragraphs = $("p");
  662. $paragraphs.each(function(index, element){
  663. var $paragraph = $(element);
  664. $paragraph.text(toPigLatin($paragraph.text()));
  665. });
  666.  
  667. </script>
  668.  
  669. </body>
  670. </html>
  671.  
  672.  
  673. <script>
  674. var $heading = $('h1');
  675. var heading = $heading[0];
  676. var $heading = $(heading);
  677.  
  678. $("p").each(function(index, element) {
  679. $(elem).text( $(element).text() + "!!");
  680. });
  681.  
  682.  
  683. $("p").each(function() {
  684. $(elem).text( $(this).text() + "!!");
  685. });
  686.  
  687. </script>
  688.  
  689.  
  690. <!DOCTYPE html>
  691. <html>
  692. <head>
  693. <meta charset="utf-8">
  694. <title>Chaining jQuery methods</title>
  695. <style>
  696. .crocodile {
  697. color: green;
  698. font-family: fantasy;
  699. }
  700. </style>
  701. </head>
  702. <body>
  703.  
  704. <h2 id="cuteness">Cats are cute!</h2>
  705.  
  706. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  707.  
  708. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  709. <a href="https://en.wikipedia.org/wiki/Cat_food">
  710. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  711. </a>
  712.  
  713. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  714.  
  715. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  716. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  717.  
  718. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  719.  
  720. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  721. <script>
  722. // Modifying elements
  723. $("h2").text("CROCODILE ATTACK!");
  724. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  725. $("p").css("color", "green");
  726. $("h2").addClass("crocodile");
  727. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  728. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  729.  
  730. // Creating elements
  731. var newP = $("<p>");
  732. newP.text("The crocodiles have eaten this ENTIRE PAGE!");
  733. newP.addClass("crocodile");
  734. $("body").append(newP);
  735.  
  736. //chaining
  737. $("<p>")
  738. .text("The crocodiles have eaten this ENTIRE PAGE!")
  739. .addClass("crocodile")
  740. .appendTo("body");
  741.  
  742. </script>
  743. </body>
  744. </html>
  745.  
  746.  
  747.  
  748. <!DOCTYPE html>
  749. <html>
  750. <head>
  751. <meta charset="utf-8">
  752. <title>Challenge: Daisy chain</title>
  753. </head>
  754. <body>
  755.  
  756.  
  757. <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
  758. <script>
  759. // You can use the daisy image at:
  760. // https://upload.wikimedia.org/wikipedia/commons/2/29/English_Daisy_(Bellis_Perennis).jpg
  761. for (var i = 0; i < 5; i +=1)
  762. {
  763. $("<img>")
  764. .attr("src", "https://upload.wikimedia.org/wikipedia/commons/2/29/English_Daisy_(Bellis_Perennis).jpg")
  765. .attr("width", 100)
  766. .attr("alt", "Daisies")
  767. .appendTo("body")
  768. }
  769. </script>
  770. </body>
  771. </html>
  772.  
  773.  
  774. <!DOCTYPE html>
  775. <html>
  776. <head>
  777. <meta charset="utf-8">
  778. <title>Adding event listeners with jQuery</title>
  779. <style>
  780. .crocodile {
  781. color: green;
  782. font-family: fantasy;
  783. }
  784. </style>
  785. </head>
  786. <body>
  787.  
  788. <button id = "a-button"> A Button</button>
  789.  
  790. <h2 id="cuteness">Cats are cute!</h2>
  791.  
  792. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  793.  
  794. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  795. <a href="https://en.wikipedia.org/wiki/Cat_food">
  796. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  797. </a>
  798.  
  799. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  800.  
  801. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  802. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  803.  
  804. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  805.  
  806. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  807. <script>
  808.  
  809. var crocodilize = function()
  810. {
  811. // Modifying elements
  812. $("h2").text("CROCODILE ATTACK!");
  813. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  814. $("p").css("color", "green");
  815. $("h2").addClass("crocodile");
  816. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  817. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  818. };
  819.  
  820. $("#a-button").on("click", function()
  821. {
  822. console.log("a string");
  823. crocodilize();
  824. });
  825.  
  826.  
  827. </script>
  828. </body>
  829. </html>
  830.  
  831.  
  832.  
  833.  
  834. <!DOCTYPE html>
  835. <html>
  836. <head>
  837. <meta charset="utf-8">
  838. <title>Challenge: Croc Clicker</title>
  839. </head>
  840. <body>
  841.  
  842. <h1>Challenge: Croc Clicker</h1>
  843. <img id="crocs" src="https://www.kasandbox.org/programming-images/animals/crocodiles.png" width="300" alt="Crocodiles chilling">
  844. <div id="results"></div>
  845. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  846. <script>
  847. var numClicks = 0;
  848. $("#results").text("You clicked " + numClicks + " times");
  849. $("img").on("click", function()
  850. {
  851. numClicks++;
  852. $("#results").text("You clicked " + numClicks + " times");
  853. });
  854. </script>
  855.  
  856.  
  857. </body>
  858. </html>
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865. <!DOCTYPE html>
  866. <html>
  867. <head>
  868. <meta charset="utf-8">
  869. <title>Using event properties in jQuery</title>
  870. <style>
  871. .crocodile {
  872. color: green;
  873. font-family: fantasy;
  874. }
  875. </style>
  876. </head>
  877. <body>
  878. <h2 id="cuteness">Cats are cute!</h2>
  879.  
  880. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  881.  
  882. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  883. <a href="https://en.wikipedia.org/wiki/Cat_food">
  884. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  885. </a>
  886.  
  887. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  888.  
  889. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  890. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  891.  
  892. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  893.  
  894. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  895. <script>
  896.  
  897. var crocodilize = function() {
  898. $("h2").text("CROCODILE ATTACK!");
  899. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  900. $("p").css("color", "green");
  901. $("h2").addClass("crocodile");
  902. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  903. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  904. };
  905.  
  906. crocodilize();
  907.  
  908. // When the user clicks on the page:
  909.  
  910. // create a new image
  911. // position it according to where click happened
  912. $("body").on("click", function(event)
  913. {
  914. console.log(event);
  915. var $img = $("<img>")
  916. .attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png")
  917. .width(100)
  918. .css("position", "absolute")
  919. .css("top", event.pageY + "px")
  920. .css("left", event.pageX + "px")
  921. .appendTo("body");
  922. });
  923.  
  924. </script>
  925. </body>
  926. </html>
  927.  
  928.  
  929.  
  930. <!DOCTYPE html>
  931. <html>
  932. <head>
  933. <meta charset="utf-8">
  934. <title>Challenge: Spot the Dog</title>
  935. <style>
  936. .dot {
  937. border-radius: 10px;
  938. background: black;
  939. position: absolute;
  940. width: 10px;
  941. height: 10px;
  942. }
  943. </style>
  944. </head>
  945. <body>
  946.  
  947. <img id="dog-pic" src="https://upload.wikimedia.org/wikipedia/commons/a/aa/Alopekis_white_male.jpg" width="500" alt="White dog">
  948.  
  949. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  950. <script>
  951. $("#dog-pic").on("click", function(event) {
  952. var $dot = $("<div></div>");
  953. $dot.addClass("dot");
  954. $dot.appendTo("body");
  955. dot.css("top", event.pageY + "px")
  956. dot.css("left", event.pageX + "px")
  957.  
  958. });
  959.  
  960. </script>
  961.  
  962.  
  963. </body>
  964. </html>
  965.  
  966.  
  967.  
  968.  
  969. <!DOCTYPE html>
  970. <html>
  971. <head>
  972. <meta charset="utf-8">
  973. <title>Checking DOM readiness with jQuery</title>
  974. <style>
  975. .crocodile {
  976. color: green;
  977. font-family: fantasy;
  978. }
  979. </style>
  980.  
  981. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  982. <script>
  983.  
  984. var crocodilize = function() {
  985. $("h2").text("CROCODILE ATTACK!");
  986. $("p").html("The crocodiles are coming - <strong>oh noess</strong>!!");
  987. $("p").css("color", "green");
  988. $("h2").addClass("crocodile");
  989. $("a").attr("href", "https://en.wikipedia.org/wiki/Crocodile");
  990. $("img").attr("src", "https://www.kasandbox.org/programming-images/animals/crocodiles.png");
  991. };
  992.  
  993. crocodilize();
  994. $(document).ready(function()
  995. {
  996. crocodilize();
  997. });
  998. </script>
  999.  
  1000. </head>
  1001. <body>
  1002.  
  1003. <h2 id="cuteness">Cats are cute!</h2>
  1004.  
  1005. <p>Cats are widely known to be one of the cutest animals. It has long been rumored that they have put all of humanity under a hypnosis, so that they can achieve their goals of getting fed while also getting to do whatever they darn want around our houses.</p>
  1006.  
  1007. <p>This cat is exhibiting what's known as the "so-cute-now-feed-me" face:</p>
  1008. <a href="https://en.wikipedia.org/wiki/Cat_food">
  1009. <img src="https://www.kasandbox.org/programming-images/animals/cat.png" width="50">
  1010. </a>
  1011.  
  1012. <h2 id="activities">Common cat activities (Cat-ivities)</h2>
  1013.  
  1014. <p>Cats enjoy attacking innocent pieces of string, walking around your legs at the exact moment that you're trying to flip a pancake on the stove, sleeping for hours and hours and hours, and pouncing on unsuspecting laser dots.</p>
  1015. <img src="https://upload.wikimedia.org/wikipedia/commons/5/5c/2006-07-07_katze_mit_angel.jpg" width="50">
  1016.  
  1017. <a href="https://en.wikipedia.org/wiki/Cat">Learn more</a>
  1018.  
  1019.  
  1020. </body>
  1021. </html>
  1022.  
  1023. <script>
  1024. $("#save-button").on("click", function() {
  1025. // handle click event
  1026. });
  1027.  
  1028. $("#face-pic").on("click", function(event) {
  1029. var mouseX = event.pageX;
  1030. var mouseY = event.pageY;
  1031. });
  1032.  
  1033. $("#save-button").trigger("click");
  1034.  
  1035. $(document).ready(function() {
  1036. $("h1").text("Y'all ready for this?");
  1037. });
  1038.  
  1039. $(function() {
  1040. $("h1").text("Y'all ready for this?");
  1041. });
  1042. </script>
  1043.  
  1044.  
  1045.  
  1046. <!DOCTYPE html>
  1047. <html>
  1048. <head>
  1049. <meta charset="utf-8">
  1050. <title>Processing a quiz with jQuery</title>
  1051. </head>
  1052. <body>
  1053.  
  1054. <h1>Reptile quiz</h1>
  1055.  
  1056. <form id="quiz-form">
  1057. <label>
  1058. What is this? <br>
  1059. <img src="https://ka-perseus-images.s3.amazonaws.com/325aab611b8b69b51bfeb16ade0af741da7dc3ff.jpg" alt="Reptile"> <br>
  1060. <select id="quiz-answer">
  1061. <option value="crocodile">Crocodile</option>
  1062. <option value="alligator">Alligator</option>
  1063. <option value="caiman">Caiman</option>
  1064. </select>
  1065. </label> <br>
  1066. <button type="submit">Check Answer</button>
  1067. </form>
  1068. <div id="result"></div>
  1069.  
  1070. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  1071. <script>
  1072.  
  1073. // When the user submits the form,
  1074. // Check what answer they picked
  1075. // And tell them if they're correct
  1076. $("#quiz-form").on("submit", function(event)
  1077. {
  1078. event.preventDefault();
  1079. var $answer = $("#quiz-answer");
  1080. var answer = $answer.val();
  1081. console.log(answer);
  1082. if (answer === "crocodile")
  1083. {
  1084. $("#result").text("this is a answer");
  1085. else
  1086. {
  1087. $("result").text("try it again?");
  1088. }
  1089. }
  1090. });
  1091.  
  1092. </script>
  1093. </body>
  1094. </html>
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104. <!DOCTYPE html>
  1105. <html>
  1106. <head>
  1107. <meta charset="utf-8">
  1108. <title>Challenge: jQuery trivia quiz</title>
  1109. <style>
  1110. #result {
  1111. background: rgb(255, 246, 204);
  1112. border: 2px dotted gold;
  1113. font-size: 24px;
  1114. height: 60px;
  1115. margin-top: 10px;
  1116. }
  1117. </style>
  1118. </head>
  1119. <body>
  1120.  
  1121. <h1>jQuery Quiz</h1>
  1122.  
  1123. <form id="trivia-form">
  1124. <label>
  1125. Who invented jQuery?<br>
  1126. <select id="trivia-answer">
  1127. <option value="eich">Brendan Eich</option>
  1128. <option value="resig">John Resig</option>
  1129. <option value="rossum">Guido van Rossum</option>
  1130. <option value="berners">Tim Berners-Lee</option>
  1131. </select>
  1132. </label> <br>
  1133. <button type="submit">Check Answer</button>
  1134. </form>
  1135. <div id="result"></div>
  1136.  
  1137. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  1138. <script>
  1139. $("#trivia-form").on("submit", function(event)
  1140. {
  1141. event.preventDefault();
  1142.  
  1143. var $answer = $("#trivia-answer");
  1144. var answer = $answer.val();
  1145.  
  1146. if (answer === "resig")
  1147. {
  1148. $("#result").text("autism");
  1149. }
  1150. else
  1151. {
  1152. $("#result").text("try again");
  1153. }
  1154.  
  1155. });
  1156. </script>
  1157. </body>
  1158. </html>
  1159.  
  1160.  
  1161.  
  1162.  
  1163. <!DOCTYPE html>
  1164. <html>
  1165. <head>
  1166. <meta charset="utf-8">
  1167. <title>More form processing with jQuery</title>
  1168. </head>
  1169. <body>
  1170.  
  1171. <h1>Crocodile order form</h1>
  1172.  
  1173. <form id="croc-form">
  1174. <label>
  1175. Species?
  1176. <select name="species">
  1177. <option value="freshwater">Freshwater crocodile</option>
  1178. <option value="saltwater">Saltwater crocodile</option>
  1179. <option value="american">American crocodile</option>
  1180. </select>
  1181. </label>
  1182. <button type="submit">Order</button>
  1183. </form>
  1184.  
  1185. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  1186. <script>
  1187. // Maps croc species to image URLs
  1188. var crocImages = {
  1189. "american": "https://upload.wikimedia.org/wikipedia/commons/f/f2/Crocodylus_acutus_mexico_02-edit1.jpg",
  1190. "saltwater": "https://upload.wikimedia.org/wikipedia/commons/c/ca/Crocodylus_porosus_4.jpg",
  1191. "freshwater": "https://upload.wikimedia.org/wikipedia/commons/c/ce/Australia_Cairns_18.jpg"
  1192. };
  1193.  
  1194. // When the user submits the form,
  1195. // Check what species they ordered
  1196. // and display an image of it
  1197.  
  1198. $("#croc-form").on("submit", function(event)
  1199. {
  1200. event.preventDefault();
  1201. var $crocSpecies = $("#croc-form [name = species]");
  1202. $(this).find("[name = species]"); // DOM element
  1203.  
  1204. var crocSpecies = $crocSpecies.val();
  1205. var $img = $("zimg>");
  1206. $img.width(100);
  1207. $img.attr("src", crocImages[crocSpecies]);
  1208. $img.appendTo("body");
  1209. });
  1210. </script>
  1211. </body>
  1212. </html>
  1213.  
  1214.  
  1215.  
  1216.  
  1217. <!DOCTYPE html>
  1218. <html>
  1219. <head>
  1220. <meta charset="utf-8">
  1221. <title>Challenge: Donut Calculator</title>
  1222. </head>
  1223. <body>
  1224.  
  1225. <h1>Donut Calculator</h1>
  1226.  
  1227. <p>Winston eats 3 donuts a day. How many donuts will he eat in his lifetime?</p>
  1228.  
  1229. <form id="calculator-form">
  1230. <label>
  1231. Winston's final age:
  1232. <input type="number" name="age">
  1233. </label>
  1234. <button type="submit">Calculate</button>
  1235. <div id="calculator-results"></div>
  1236. </form>
  1237.  
  1238. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  1239. <script>
  1240. var calcDonuts = function(years) {
  1241. return years * 3 * 365;
  1242. };
  1243.  
  1244. $("#calculator-form").on("submit", function(event) {
  1245. event.preventDefault();
  1246.  
  1247. // TODO: Find inputted age, calculate # of donuts
  1248. var $age = $(this).find("[name = age]");
  1249. var Age = $age.val();
  1250. var total = calcDonuts(Age);
  1251.  
  1252. $("#calculator-results").text("Winston ate "+ total );
  1253. });
  1254. </script>
  1255. </body>
  1256. </html>
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262. <script>
  1263. $("form").on("submit", function() {
  1264. // process form
  1265. });
  1266.  
  1267. $("form").on("submit", function(event) {
  1268. event.preventDefault();
  1269. // process form
  1270. });
  1271.  
  1272. var answer = $("#answer").val();
  1273.  
  1274. $("form").on("submit", function() {
  1275. // store the value of the input with name='age'
  1276. var age = $(this).find('[name=age]').val();
  1277. });
  1278. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement