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
// creates a function that will add a 2px blue border around each div with the class "blue" | |
$.fn.blueBorder = function(){ | |
this.each(function(){ | |
$(this).css("border","solid blue 2px"); | |
}); | |
return this; | |
}; | |
//creates a function that will turn the text color blue of each div | |
$.fn.blueText = 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
// this targets Google Chrome and Opera 18+ | |
var isChromium = window.chrome; | |
if(isChrome === true) { | |
// is chromium based browser | |
} else { | |
// not chromium based browser | |
} | |
//To target if the browser is Google Chrome, use this: | |
var isChromium = window.chrome, |
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 myFunc; | |
var num = 0; | |
if (num === 0){ | |
myFunc = function(theObject) { | |
theObject.make = "Toyota"; | |
theObject.year = "2003"; | |
return theObject; | |
}; | |
} |
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 square = function(number) {return number * number}; | |
var x = square(4) //x gets the value 16 |
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
//put this in the console | |
monitorEvents(window) | |
//only mouse events | |
monitorEvents(window, 'mouse') | |
//only keyboard events | |
monitorEvents(window, 'key') | |
//only scroll activity |
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
$('body').on({ | |
click: function() { | |
event.preventDefault(); | |
console.log('item anchor clicked'); | |
}, | |
mouseenter: function() { | |
console.log('enter!'); | |
} | |
}); |
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
// Arrays | |
var trees = new Array("redwood", "bay", "cedar", "oak", "maple"); | |
0 in trees; // returns true | |
3 in trees; // returns true | |
6 in trees; // returns false | |
"bay" in trees; // returns false (you must specify the index number, | |
// not the value at that index) | |
"length" in trees; // returns true (length is an Array property) | |
// Predefined objects |
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
//The delete operator deletes an object, an object's property, or an element at a specified index in an array. Syntax: | |
delete objectName; | |
delete objectName.property; | |
delete objectName[index]; | |
delete property; // legal only within a with statement | |
//If the delete operator succeeds, it sets the property or element to undefined. | |
//The delete operator returns true if the operation is possible; it returns false if the operation is not possible. | |
x = 42; |
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 age = 19; | |
if(age >= 18){ | |
var status = "adult"; | |
}else{ | |
var status = "minor"; | |
} | |
//short hand version | |
var status = (age >= 18) ? "adult" : "minor"; |
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
if (cond) var x = {hi: "there"}; |