Advertisement
Crevice

jQuery Exercise

Nov 6th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <script src="https://code.jquery.com/jquery-3.4.1.min.js"
  9. integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  10. <style>
  11. .color-box {
  12. height: 200px;
  13. width: 200px;
  14. display: inline-block;
  15. margin: 50px;
  16. }
  17. .large-color-box {
  18. height: 500px;
  19. width: 500px;
  20. display: inline-block;
  21. margin: 50px;
  22. }
  23. .red {
  24. background-color: red;
  25. }
  26. .blue {
  27. background-color: blue;
  28. }
  29. .green {
  30. background-color: green;
  31. }
  32. </style>
  33. <script>
  34. $(document).ready(initializeApp)
  35. function initializeApp() {
  36. $("button").click(makeStuffHappen);
  37. }
  38. // EXERCISE STARTS HERE ----------------------------------------------
  39. function makeStuffHappen() {
  40. //utilize the jQuery function to select all h1 elements on the DOM (there is currently just one)
  41. //save the return from this into a variable named headerElem
  42. //utilize the jQuery function to select all input elements on the DOM (there is currently just one)
  43. //save the return from this into a variable named inputElem
  44. //utilize the jQuery function to select all elements with a class of "color-box" that do not have a class of "no-change"
  45. //remember, the string selector given to the jQuery function works exactly the same as a CSS selector
  46. //HINT: look into the ":not" pseudoclass
  47. //save the return from this into a variable named boxesToChange
  48. //console.log out your headerElem and boxesToChange variables
  49. //what's inside of them?
  50. //using your inputElem variable, retrieve the current value out of the input, and save it into a variable called currentVal
  51. //HINT: look into the jQuery .val method
  52. // using your headerElem variable, change the text content of the element to the value of the currentVal variable
  53. //HINT: look into the jQuery .text method
  54. // using your boxesToChange variable, remove the class "color-box" and the class "red" from the selected element(s), and add the class "large-color-box" and a class of "blue"
  55. //console log our your boxesToChange variable
  56. //remember that we selected this dom element by using the "color-box" class initially
  57. //now that we have removed the "color-box" class, does the variable still contain the same element?
  58. }
  59. </script>
  60. </head>
  61. <body>
  62. <h1>I'm the main heading! My text content will definitely stay the same forever!</h1>
  63. <div>
  64. <input type="text" value="HAXXORED!!1!">
  65. <button>Click me!</button>
  66. </div>
  67. <div class="color-box red"></div>
  68. <div class="color-box red no-change"></div>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement