
Glad you could make it! We start with some context about how we'll be approaching JQUERY and what you can use this wonderful API for.
index.html
<!-- JavaScript --><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
index.html
<!-- CSS --><link href="styles.css" rel="stylesheet"><link href="lightbox2-master/dist/css/lightbox.css" rel="stylesheet">
and
<!-- JavaScript --><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><script src="lightbox2-master/dist/js/lightbox.js"></script>
http://lokeshdhakar.com/projects/lightbox2/
index.html
<a href="assets/images/image1.jpg" data-lightbox="image1" data-title="My caption"> <img src="assets/thumbnails/thumbs/thumb1.jpg" alt="Surfing"></a>
Add this <a> tag to each image on your page, but remember to change the path each time.
index.html
<a href="assets/images/image1.jpg" data-lightbox="roadtrip" data-title="My caption"> <img src="assets/thumbnails/thumbs/thumb1.jpg" alt="Surfing"></a>
index.html
<a href="assets/images/image1.jpg" data-lightbox="roadtrip" data-title="Surfing"> <img src="assets/thumbnails/thumbs/thumb1.jpg" alt="Surfing"></a>
index.html
<!-- JavaScript -->...<script> lightbox.option({ 'positionFromTop': 200 })</script> What was the greatest vacation you've ever taken? Or where is somewhere you've always dreamed of going?
This challenge is going to focus on customizing your Lightbox to share images of your dream vacation.
Don't forget to download the starter code!
Click here to download the starter code folder.
Windows shortcut: Select code block, then Control + /
Mac Shortcut: Select code block, then Command + /
styles.css
/*.collapse { display: none;}*/
Windows shortcut: Click on file in appropriate folder, then Control + N
Mac Shortcut: Click on file in appropriate folder, then Command + N
Save as "index.js"
index.html
<!-- JavaScript --><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><script src="index.js"></script>
Resources:
index.html
<div id="q1" class="question">1. What is jQuery?
index.js
$("#q1")index.js
$("#q1").click(function() { console.log($("#q1"));})
index.html
<div id="a1" class="answer collapse">
index.js
$("#q1").click(function() { $("#a1");})
index.js
$("#q1").click(function() { $("#a1").slideDown("slow");})
index.js
$("#q1").click(function() { $("#a1").slideToggle("slow");})
index.js
$("#q1").click(function() { $("#a1").fadeToggle("slow");})index.html
<img id="arrow1-down" class="arrow down" src ="assets/arrow-down.svg"><img id="arrow1-up" class="arrow up" src ="assets/arrow-up.svg">
index.js
$("#q1").click(function() { $("#a1").fadeToggle("fast"); $("#arrow1-down").toggleClass("collapse"); $("#arrow1-up").toggleClass("collapse");})
index.js
$("#q1").click(function() { $("#a1").fadeToggle("fast"); $("#arrow1-down, #arrow1-up").toggleClass("collapse");})
index.js
$("#q1").click(function() { $("#a1").fadeToggle("fast"); $("#arrow1-down, #arrow1-up").toggleClass("collapse");})$("#q2").click(function() { $("#a2").fadeToggle("fast"); $("#arrow2-down, #arrow2-up").toggleClass("collapse");})$("#q3").click(function() { $("#a3").fadeToggle("fast"); $("#arrow3-down, #arrow3-up").toggleClass("collapse");})Resources:
index.js
$("#q1").click(function() { console.log($(this)); // $("#a1").fadeToggle("fast"); // $("#arrow1-down, #arrow1-up").toggleClass("collapse");})
index.js
$(".question").click(function() { console.log($(this)); // $("#a1").fadeToggle("fast"); // $("#arrow1-down, #arrow1-up").toggleClass("collapse");})// $("#q2").click(function() {// $("#a2").fadeToggle("fast");// $("#arrow2-down, #arrow2-up").toggleClass("collapse");// })// $("#q3").click(function() {// $("#a3").fadeToggle("fast");// $("#arrow3-down, #arrow3-up").toggleClass("collapse");// })
index.js
$(".question").click(function() { console.log($(this).next()); // $("#a1").fadeToggle("fast"); // $("#arrow1-down, #arrow1-up").toggleClass("collapse");})
index.js
$(".question").click(function() { $(this).next().fadeToggle("fast"); console.log($(this).children()); // $("#a1").fadeToggle("fast"); // $("#arrow1-down, #arrow1-up").toggleClass("collapse");})
index.js
$(".question").click(function() { $(this).next().fadeToggle("fast"); $(this).children().toggleClass("collapse");})Now that we're half-way through the course (!), we review what we've learned so far and cover the project we're about to build. Put it on your to-do list.
Don't forget to use the starter code (download here)!
jQuery code likes to be loaded early in the page, after the document is ready. This is why we add our custom jQuery code after (document).ready !
index.js
$(document).ready(function () { $(".add-items").submit(function() { console.log("HI!";) });});
index.js
$(document).ready(function () { $(".add-items").submit(function(event) { event.preventDefault(); console.log("HI!"); });});index.html
<input type="text" class="form control" id="todo-list-item" placeholder="what do you need to do today?">
index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); console.log($("#todo-list-item").val()); });});
index.js
var item = $("#todo-list-item").val(); });index.html
<ul id="list-items">
index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); $("#list-items").append("<li>" + item + "</li>"); });});
index.js
$("#list-items").append("<li><input type='checkbox'/>" + item + "<a class='remove'>x</a></li>"); });
index.js
$("#list-items").append("<li><input type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); });
index.js
$("#list-items").append("<li><input type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); $("#todo-list-item").val(""); });index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); if (item) { $("#list-items").append("<li><input type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); $("#todo-list-item").val(""); } });});index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); if (item) { $("#list-items").append("<li><input class='checkbox' type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); $("#todo-list-item").val(""); } }); $(".checkbox")});
index.js
$(".checkbox").change(function() { console.log("Checkbox checked!"); })
index.js
// $(".checkbox").change(function() { // console.log("Checkbox checked!"); // }) $(document).on("change", ".checkbox", function() { });index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); if (item) { $("#list-items").append("<li><input class='checkbox' type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); $("#todo-list-item").val(""); } }); // $(".checkbox").change(function() { // console.log("Checkbox checked!"); // }) $(document).on("change", ".checkbox", function() { $(this).parent().toggleClass("completed"); });});index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); if (item) { $("#list-items").append("<li><input class='checkbox' type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); $("#todo-list-item").val(""); } }); // $(".checkbox").change(function() { // console.log("Checkbox checked!"); // }) $(document).on("change", ".checkbox", function() { $(this).parent().toggleClass("completed"); }); $(document).on("click", ".remove", function() { $(this).parent().remove(); });});index.js
$(document).ready(function () { $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); if (item) { $("#list-items").append("<li><input class='checkbox' type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); localStorage.setItem("listItems", $("#list-items").html()); $("#todo-list-item").val(""); } }); // $(".checkbox").change(function() { // console.log("Checkbox checked!"); // }) $(document).on("change", ".checkbox", function() { $(this).parent().toggleClass("completed"); }); $(document).on("click", ".remove", function() { $(this).parent().remove(); });});
index.js
$(document).ready(function () { $("#list-items").html(localStorage.getItem("listItems")); $(".add-items").submit(function (event) { event.preventDefault();index.js
$(document).ready(function () { $("#list-items").html(localStorage.getItem("listItems")); $(".add-items").submit(function (event) { event.preventDefault(); var item = $("#todo-list-item").val(); if (item) { $("#list-items").append("<li><input class='checkbox' type='checkbox'/>" + item + "<a class='remove'>x</a><hr></li>"); localStorage.setItem("listItems", $("#list-items").html()); $("#todo-list-item").val(""); } }); // $(".checkbox").change(function() { // console.log("Checkbox checked!"); // }) $(document).on("change", ".checkbox", function() { $(this).parent().toggleClass("completed"); localStorage.setItem("listItems", $("#list-items").html()); }); $(document).on("click", ".remove", function() { $(this).parent().remove(); localStorage.setItem("listItems", $("#list-items").html()); });});
index.js
$(document).on("change", ".checkbox", function() { if ($(this).attr("checked")) { $(this).removeAttr("checked"); } else { $(this).attr("checked", "checked"); } $(this).parent().toggleClass("completed"); localStorage.setItem("listItems", $("#list-items").html()); })
listItem === "dance", append a dance GIF to the todo list. Have fun with it!Welcome to our final project! We're going to build our most complex and realistic application yet, so check out this video for a roadmap of where we're going.
Don't forget to use the starter code (download here)!
Link to JSON file: https://api.myjson.com/bins/2sadq?pretty=1
You can get the starter code here!
Link to JSON file: https://api.myjson.com/bins/2sadq?pretty=1
index.js
$(document).ready(function() { $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { debugger; } })});index.js
$(document).ready(function() { $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { $.each(response.apartments, function(i, apartment) { debugger; }); } })})<div class="list-group">
<a href="#" class="list-group-item active">
<h4 class="list-group-item-heading">List group item heading</h4>
<p class="list-group-item-text">...</p>
</a>
</div>
1. Add Bootstrap styling
index.js
$(document).ready(function() { $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { $.each(response.apartments, function(i, apartment) { <a href="#" class="list-group-item active"> <h4 class="list-group-item-heading">List group item heading</h4> <p class="list-group-item-text">...</p> </a> }); } })})
2. Add variable and change " to '
$.each(response.apartments, function(i, apartment) { var listing = "<a href='#' class='list-group-item'><h4 class='list-group-item-heading'></h4><p class='list-group-item-text'></p></a>"
3. Add variable input and concatenation so it displays properly
$.each(response.apartments, function(i, apartment) { var listing = "<a href='#' class='list-group-item'><h4 class='list-group-item-heading'>" + apartment.description + "</h4><p class='list-group-item-text'></p></a>"; $(".apartments").append(listing);
4. Extra styling
$.each(response.apartments, function(i, apartment) { var listing = "<a href='#' class='list-group-item'><h4 class='list-group-item-heading'>" + apartment.description + " / " + apartment.bedrooms + " / " + apartment.price + "</h4><p class='list-group-item-text'>" + apartment.neighborhood + "</p></a>"; $(".apartments").append(listing);1. Add error logging and "BR" to apartment listing
index.js
$(document).ready(function() { $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { $.each(response.apartments, function(i, apartment) { var listing = "<a href='#' class='list-group-item'><h4 class='list-group-item-heading'>" + apartment.description + " / " + apartment.bedrooms + " BR / " + apartment.price + "</h4><p class='list-group-item-text'>" + apartment.neighborhood + "</p></a>"; $(".apartments").append(listing); }); }, error: function(error) { console.log(error); } });})
2. Start using borough ID to create a class and filter listings
error: function(error) { console.log(error); } }); $(".filter").click(function() { });})Resources:
1. Implement city ID as class for filtering
index.js
$(".filter").click(function() { var city = $(this).attr("id"); });});
2. Filter out cities that DON'T match our selected borough, add listings class, and apartmentClass variable.
$(document).ready(function() { $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { $.each(response.apartments, function(i, apartment) { var apartmentClass = apartment.city.toLowerCase().replace(" ", "-"); var listing = "<a href='#' class='list-group-item " + apartmentClass + " listings'><h4 class='list-group-item-heading'>" + apartment.description + " / " + apartment.bedrooms + " BR / " + apartment.price + "</h4><p class='list-group-item-text'>" + apartment.neighborhood + "</p></a>"; $(".apartments").append(listing); }); }, error: function(error) { console.log(error); } }); $(".filter").click(function() { var city = $(this).attr("id"); $(".listings").not("." + city).css("display", "none"); });});Resources:
1. Show all listings before hiding filtered listings
index.js
$(".filter").click(function() { var city = $(this).attr("id"); $(".listings").show(); $(".listings").not("." + city).css("display", "none"); });});
2. Add conditional so all listings can be displayed
$(".filter").click(function() { var city = $(this).attr("id"); $(".listings").show(); if (city !== "all") { $(".listings").not("." + city).css("display", "none"); } });});
3. Remove active class when new filter is clicked, add it to correct filter, tidy up code
$(".filter").click(function() { $(".filter").removeClass("active"); $(this).addClass("active"); $(".listings").show(); var city = $(this).attr("id"); if (city !== "all") { $(".listings").not("." + city).css("display", "none"); } });});
Resources:
1. Add skeleton of function that happens when a listing is clicked
index.js
$(document).ready(function() { $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { $.each(response.apartments, function(i, apartment) { var apartmentClass = apartment.city.toLowerCase().replace(" ", "-"); var listing = "<a href='#' class='list-group-item " + apartmentClass + " listings'><h4 class='list-group-item-heading'>" + apartment.description + " / " + apartment.bedrooms + " BR / " + apartment.price + "</h4><p class='list-group-item-text'>" + apartment.neighborhood + "</p></a>"; $(".apartments").append(listing); }); }, error: function(error) { console.log(error); } }); $(".filter").click(function() { $(".filter").removeClass("active"); $(this).addClass("active"); $(".listings").show(); var city = $(this).attr("id"); if (city !== "all") { $(".listings").not("." + city).css("display", "none"); } }); $(document).on("click", ".listings", function(){ });});
2. Add unique identifier to each apartment listing
var listing = "<a href='#' id=" + apartment.id + " class='list-group-item " + apartmentClass + " listings'><h4 class='list-group-item-heading'>" + apartment.description + " / " + apartment.bedrooms + " BR / " + apartment.price + "</h4><p class='list-group-item-text'>" + apartment.neighborhood + "</p></a>";
3. Find the apartment info that matches the ID of the listing that was clicked, add debugging
$(document).on("click", ".listings", function(){ var id = $(this).attr("id"); $.ajax({ url: "https://api.myjson.com/bins/2sadq?pretty=1", dataType: "json", success: function(response) { var selectedApartment = $.grep(response.apartments, function(apartment){ return apartment.id == id; }) debugger; }, error: function(error) { console.log(error); } }); });});
4. Add address variable which stores the address of the clicked apartment
success: function(response) { var selectedApartment = $.grep(response.apartments, function(apartment){ return apartment.id == id; }) var address = selectedApartment[0].address;}
5. Open selected address using Google Maps in a new browser tab
success: function(response) { var selectedApartment = $.grep(response.apartments, function(apartment){ return apartment.id == id; }) var address = selectedApartment[0].address; window.open("http://maps.google.com/?q=" + address);},We're at the end of jQUERY. Well done! This door has closed, but now many others are now open to you.
You up for one more challenge? We can make our application more interesting and unique with Javascript from bootstrap. And then you can submit your ideas to OneMonth/brag about your modal jQUERY mastery.
<script> tag to the <head> with the Bootstrap CDN link of the "Latest compiled and minified JavaScript"Do you have a website, but can’t figure out how to make it interactive by adding forms, drop-down menus, or filtering lists? Had a hard time trying to learn jQuery or JavaScript in the past? Feeling totally in the deep end? By learning jQuery with One Month you can easily change that.
One Month jQuery is a series of video lessons and tutorials that show anyone -- even a total beginner -- how to build four real-world projects that you can add to your website. You will learn how to make your website more interactive and engaging using jQuery.
When you sign up, you immediately get access to a member’s area where you can learn jQuery online and take each lesson at your own pace. Through engaging iQuery tutorials, you’ll learn how to interact with the Document Object Model (DOM), use web developer tools, and get started with reading and understanding documentation to help you take the reins of your own projects -- sounds fancy, huh? We promise that it’s not as complicated as it sounds. Each lesson acts as a jQuery tutorial for beginners as we break everything down along the way making it easier than ever to learn jQuery online.