Javascript Flashcards
D3: A good way to visualize binned data is
as shapes.
D3: The three most popular D3 libraries are
dimple.js, Rickshaw, NVD3
D3: The best D3 library for time series or streaming data is
Rickshaw
D3: The DOM gets created during
page load
Javascript: To clear the javascript console, type
clear()
Javascript: In the javascript console, to return the html of the current page that has a certain css id, type
document.getElementById(“cssid”)
Javascript: In the javascript console, to return the html of the current page that has a any css selector, type
document.querySelector(“.css-class”)
D3: To select elements using D3, type
d3.select(“.css-class”)
D3: To select a DOM element and then change its css styled color, type
d3.select(“.css-class”).style(“background-color”, “green”)
D3: To check if the element you are selecting is unique, you can type
d3.selectAll(“.css-class”)
and then make sure the array returned has one item.
D3: To select a DOM element and then change its text, type
d3.select(“.css-class”).text(“New Text”)
D3: To select an element within your current selection, type
current_selection_var.select(“.inner-class”)
D3: To change an html attribute, type
d3.select(“.css-class”).attr(“attribute_name”, “new value”)
javascript: To set a string to uppercase, type
string_var.toUpperCase()
javascript: To create a function, type
function fuctionName() { }
javascript: To create an anonymous function, type
var functionVar = function () { };
note: requires semicolon
javascript: To create a function that returns a string, type
function fuctionName() { return "string" }
jQuery: To hide an html element with the class=”class”, type
jQuery(“.class”).hide();
jQuery: To show an html element with the class=”class” slowly, type
jQuery(“.class”).show(“slow”);
jQuery: The abbreviation for jQuery is
$
jQuery: Most jQuery methods return
the item selected, which allows for method chaining.
javascript: To return all of the html tags of the body of a page, type
document.body.children
javascript: To return all of the html tags on a page with a certain class name, type
document.getElementByClassName(“class”)
jQuery: In the jQuery docs, animations are categorized as
Effects
jQuery: To run a function when the DOM loads, type
$(document).ready(myFunction)
or
$(myFunction)
jQuery: When manipulating the DOM using javascript it is a best practice to
not create a script that runs on ready and just add your script at the bottom of the body and assume it is ready.
jQuery: To add html to an html element based on it’s class, type
$(“.class”).append(“-button>String-/button>”)
jQuery: To remove the code for the precise button you are clicking, type
$(“button”).click(function() {
$(this).remove();
});
jQuery: To traverse to the previous sibling page element before the element you selected by class, type
$(“.class”).prev()
jQuery: To prevent a link from taking you to the next page, type
$(“a”).click(function(event) {
event.preventDefault();
})
jQuery: To return the href of the link you just clicked, type
$("a").click(function() { var my_attribute = $(this).attr("href"); })
jQuery: To turn a string into a jQuery representation of a page element, type
var $my_element = $(-div>-/div>)
jQuery: To signify that a variable is a jQuery object, people ofter
add a $ to the beginning of the variable name
jQuery: The append method appends to
the end but still inside the tags you point at.
jQuery: To use attr() to add an attribute to an element, type
$(“.class”)attr(“key”, “value”);
jQuery: To append text into a tag, type
$(“.class”).text(“string”)
ajax was originally called
xml http requestobject
ajax: To make a web page know that it will work with ajax, add to the head
-script>
var xhr_object = new XMLHttpRequest();
-/script>
ajax: a good response has the readyState value of
4
ajax: the servers response is held in an attribute called
xhr_object.responseText
ajax: To create a button that triggers the send method of an xhr_object, type
function sendAjax () { xhr_object.send() }
-button onClick=”sendAjax()”>String-/button>
ajax: The steps to use ajax are
create an xhr_object
set a response function
open the request
send the request
ajax can only send requests to
one server
ajax: To overcome ajax’s one host policy you can
have your server call the additional servers.
ajax: To get images, css files and javascript files from an additional server, you can use
jsonp
javascript: To go to a different url, type
window.location.replace(“http://www.google.com”);
javascript: To return the url (including query string) of the current page, type
window.location.href
javascript: to slice a string, type
string_var.slice(1,5);
javascript: To return the index of a string, type
string_var.indexOf(“substring”);
javascript: To make a div immediately scroll itself to the bottom, type
document.getElementById(‘div-id’).scrollTop = document.getElementById(‘div-id’).scrollHeight;
javascript: To return the query string (including the “?”), type
window.location.search
AJAX: long polling is
When the client sends a request to the server and the server makes the client wait until an event occurs before sending the data back, and then the client makes another long request.
jQuery: To run a function upon every mouse movement, type
$(window).mousemove(function(event) {
console.log(event.type)
});
jQuery: To run a function when the mouse leaves the window, type
$(document).mouseleave(function(){
console.log(‘string’)
})
jQuery: To set or update a css property for a class, type
$(“.css-class”).css( “property”, “value”)