{ "name": "jQuery", "order": 5, "time": "2h", "challenges": [ { "id": "bad87fee1348bd9acdd08826", "title": "Learn how Script Tags and Document Ready Work", "description": [ "Now we're ready to learn jQuery, the most popular JavaScript tool of all time. Don't worry about JavaScript itself - we will cover it soon.", "Before we can start using jQuery, we need to add some things to our HTML.", "First, add a script element at the top of your page. Be sure to close it on the following line.", "Your browser will run any JavaScript inside a script element, including jQuery.", "Inside your script element, add this code: $(document).ready(function() { to your script. Then close it on the following line (still inside your script element) with: });", "We'll learn more about functions later. The important thing to know is that code you put inside this function will run as soon as your browser has loaded your page.", "This is important because without your document ready function, your code may run before your HTML is rendered, which would cause bugs." ], "tests": [ "assert(editor.match(/<\\/script\\s*>/g) && editor.match(//g) && editor.match(/<\\/script\\s*>/g).length === editor.match(//g).length, 'Create a script element making sure it is valid and has a closing tag.')", "assert(editor.match(/\\$\\s*?\\(\\s*?document\\)\\.ready\\s*?\\(\\s*?function\\s*?\\(\\s*?\\)\\s*?\\{/g), 'You should add $(document).ready(function() { to the beginning of your script element.')", "assert(editor.match(/\\n*?\\s*?\\}\\s*?\\);/g), 'Close your $(document).ready(function() { function with });.')" ], "challengeSeed": [ "", "", "", "", "
", "

jQuery Playground

", "
", "
", "

#left-well

", "
", " ", " ", " ", "
", "
", "
", "

#right-well

", "
", " ", " ", " ", "
", "
", "
", "
" ], "type": "waypoint", "challengeType": 0 }, { "id": "bad87fee1348bd9bedc08826", "title": "Target HTML Elements with Selectors Using jQuery", "description": [ "Now we have a document ready function.", "Now let's write our first jQuery statement. All jQuery functions start with a $, usually referred to as a dollar sign operator, or simply as bling.", "jQuery often selects an HTML element with a selector, then does something to that element.", "For example, let's make all of your button elements bounce. Just add this code inside your document ready function: $(\"button\").addClass(\"animated bounce\").", "Note that we've already included both the jQuery library and the Animate.css library in your code editor. So you are using jQuery to apply the Animate.css bounce class to your button elements." ], "tests": [ "assert($(\"button\").hasClass(\"animated\") && $(\"button\").hasClass(\"bounce\"), 'Use the jQuery addClass() function to give the classes animated and bounce to your button elements.')", "assert(!editor.match(/class.*animated/g), 'Only use jQuery to add these classes to the element.')" ], "challengeSeed": [ "fccss", " $(document).ready(function() {", "", " });", "fcces", "", "", "", "
", "

jQuery Playground

", "
", "
", "

#left-well

", "
", " ", " ", " ", "
", "
", "
", "

#right-well

", "
", " ", " ", " ", "
", "
", "
", "
" ], "type": "waypoint", "challengeType": 0 }, { "id": "bad87fee1348bd9aedc08826", "title": "Target Elements by Class Using jQuery", "description": [ "You see how we made all of your button elements bounce? We selected them with $(\"button\"), then we added some CSS classes to them with .addClass(\"animated bounce\");.", "You just used jQuery's .addClass() function, which allows you to add classes to elements.", "First, let's target your div elements with the class well by using the $(\".well\") selector.", "Note that, just like with CSS declarations, you type a . before the class's name.", "Then use jQuery's .addClass() function to add the classes animated and shake.", "For example, you could make all the elements with the class text-primary shake by adding the following to your document ready function: $(\".text-primary\").addClass(\"animated shake\");" ], "tests": [ "assert($(\".well\").hasClass(\"animated\") && $(\".well\").hasClass(\"shake\"), 'Use the jQuery addClass() function to give the classes animated and shake to all your elements with the class well.')", "assert(!editor.match(/class\\.\\*animated/g), 'Only use jQuery to add these classes to the element.')" ], "challengeSeed": [ "fccss", " $(document).ready(function() {", " $(\"button\").addClass(\"animated bounce\");", " });", "fcces", "", "", "", "
", "

jQuery Playground

", "
", "
", "

#left-well

", "
", " ", " ", " ", "
", "
", "
", "

#right-well

", "
", " ", " ", " ", "
", "
", "
", "
" ], "type": "waypoint", "challengeType": 0 }, { "id": "bad87fee1348bd9aeda08826", "title": "Target Elements by ID Using jQuery", "description": [ "You can also target elements by their id attributes.", "First target your button element with the id target3 by using the $(\"#target3\") selector.", "Note that, just like with CSS declarations, you type a # before the id's name.", "Then use jQuery's .addClass() function to add the classes animated and fadeOut.", "Here's how you'd make the button element with the id target6 fade out: $(\"#target6\").addClass(\"animated fadeOut\")." ], "tests": [ "assert($(\"#target3\").hasClass(\"animated\"), 'Select the buttonelement with the id of target3 and use the jQuery addClass() function to give it the class of animated.')", "assert(($(\"#target3\").hasClass(\"fadeOut\") || $(\"#target3\").hasClass(\"fadeout\")) && editor.match(/\\$\\(.#target3.\\)/g), 'Target the element with the id target3 and use the jQuery addClass() function to give it the class fadeOut.')", "assert(!editor.match(/class.*animated/g), 'Only use jQuery to add these classes to the element.')" ], "challengeSeed": [ "fccss", " $(document).ready(function() {", " $(\"button\").addClass(\"animated bounce\");", " $(\".well\").addClass(\"animated shake\");", "", " });", "fcces", "", "", "", "
", "

jQuery Playground

", "
", "
", "

#left-well

", "
", " ", " ", " ", "
", "
", "
", "

#right-well

", "
", " ", " ", " ", "
", "
", "
", "
" ], "type": "waypoint", "challengeType": 0 }, { "id": "bad87fee1348bd9aeda08726", "title": "Delete your jQuery Functions", "description": [ "These animations were cool at first, but now they're getting kind of distracting.", "Delete all three of these jQuery functions from your document ready function, but leave your document ready function itself intact." ], "tests": [ "assert(!editor.match(/e\"\\);/g) && !editor.match(/t\"\\);/g), 'Delete all three of your jQuery functions from your document ready function.')", "assert(editor.match(/