Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- <script src="https://code.jquery.com/jquery-3.4.1.min.js"
- integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
- <style>
- .color-box {
- height: 200px;
- width: 200px;
- display: inline-block;
- margin: 50px;
- }
- .large-color-box {
- height: 500px;
- width: 500px;
- display: inline-block;
- margin: 50px;
- }
- .red {
- background-color: red;
- }
- .blue {
- background-color: blue;
- }
- .green {
- background-color: green;
- }
- </style>
- <script>
- $(document).ready(initializeApp)
- function initializeApp() {
- $("button").click(makeStuffHappen);
- }
- // EXERCISE STARTS HERE ----------------------------------------------
- function makeStuffHappen() {
- //utilize the jQuery function to select all h1 elements on the DOM (there is currently just one)
- //save the return from this into a variable named headerElem
- //utilize the jQuery function to select all input elements on the DOM (there is currently just one)
- //save the return from this into a variable named inputElem
- //utilize the jQuery function to select all elements with a class of "color-box" that do not have a class of "no-change"
- //remember, the string selector given to the jQuery function works exactly the same as a CSS selector
- //HINT: look into the ":not" pseudoclass
- //save the return from this into a variable named boxesToChange
- //console.log out your headerElem and boxesToChange variables
- //what's inside of them?
- //using your inputElem variable, retrieve the current value out of the input, and save it into a variable called currentVal
- //HINT: look into the jQuery .val method
- // using your headerElem variable, change the text content of the element to the value of the currentVal variable
- //HINT: look into the jQuery .text method
- // 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"
- //console log our your boxesToChange variable
- //remember that we selected this dom element by using the "color-box" class initially
- //now that we have removed the "color-box" class, does the variable still contain the same element?
- }
- </script>
- </head>
- <body>
- <h1>I'm the main heading! My text content will definitely stay the same forever!</h1>
- <div>
- <input type="text" value="HAXXORED!!1!">
- <button>Click me!</button>
- </div>
- <div class="color-box red"></div>
- <div class="color-box red no-change"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement