This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var form = document.querySelector("#new-item-form"); | |
var list = document.querySelector("#todo-list"); | |
form.addEventListener("submit", formSubmitted); | |
loadList(); | |
function formSubmitted(event) { | |
event.preventDefault(); | |
// Assume that elsewhere we've defined the createItem function... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a value, "avand", to a given key, "username"... | |
localStorage.setItem("username", "avand"); | |
// Read the value of a given key... | |
var username = localStorage.getItem("username"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
navigator.geolocation.getCurrentPosition(displayCurrentPosition); | |
function displayCurrentPosition(position) { | |
var coords = position.coords; | |
console.log(coords.latitude, coords.longitude); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WHEN the page loads: | |
- Get the form | |
- Add an event listener | |
WHEN the form is submitted: | |
- Prevent the default form submission | |
- Get the value of the input | |
- Add the input's value to the end of the base URL ("https://api.github.com/users/") | |
- Make an HTTP request to the full URL | |
WHEN the response comes back: | |
- Parse the JSON string response (e.g., JSON.parse(response)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("a").css({ | |
"color": "blue", | |
"background-color": "white", | |
"border": "1px solid black" | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get all the list items, update their text, and set a class... | |
$("li").text("new text").addClass("todo") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.get("https://api.github.com/users/avand", showUserInfo); | |
function showUserInfo(response) { | |
// Handle the response... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get all the todos on the page... | |
var $listItems = $("li.todo"); | |
// Add a class to them all... | |
$listItems.addClass("complete"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Declare our get function... | |
function get(url, callback) { | |
var request = new XMLHttpRequest(); | |
request.open("GET", url, true); | |
request.addEventListener("readystatechange", handleReadyStateChange) | |
function handleReadyStateChange() { | |
if (request.readyState == 4 && request.status == 200) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li class="movie"> | |
<div class="movie-title"> | |
<a href="http://www.imdb.com/title/tt0106611" target="_blank"> | |
Cool Runnings | |
</a> | |
</div> | |
<div class="movie-release-date">1993</div> | |
</li> |