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
element.addEventListener "click", -> | |
alert "You clicked" | |
, false | |
# Select all links | |
links = document.querySelectorAll("a") | |
# For each link element | |
[].forEach.call links, (el) -> | |
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 "classList" in document.documentElement | |
# do something | |
# Adding a class | |
element.classList.add "bar" | |
# Removing a class | |
element.classList.remove "foo" | |
# Checking if has a class |
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
# Select an element | |
element = document.querySelector(".some-class") | |
# Give class "foo" to the element | |
element.className = "foo" | |
# Adding a class without replacing the current classes | |
element.className += " foo" | |
# removeClass, takes two params: element and classname |
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
# Getting the parent node | |
parent = document.querySelector("div").parentNode | |
# Getting the next node | |
next = document.querySelector("div").nextSibling | |
# Getting the previous node | |
next = document.querySelector("div").previousSibling | |
# Getting the first child element |
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
element = document.querySelector "div" | |
elements = document.querySelectorAll ".container div" | |
navigation = document.querySelector "nav" | |
links = navigation.querySelectorAll "a" | |
# This gives us simple dollar function and event binding | |
$ = document.querySelectorAll.bind document | |
Element::on = Element::addEventListener | |
# This is how you use it |
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
document.addEventListener "DOMContentLoaded", -> | |
# Code | |
, false |
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
console.log('Hello World!'); | |
//Hello World! | |
console.log('This is a string', { foo: 'bar' }, { bar: 'foo' }); | |
//This is a string Object {foo: "bar"} Object {bar: "foo"} | |
var number = 11 * 9; | |
var color = 'red'; | |
console.log('%d %s balloons', number, color); | |
//99 red balloons |
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
// ! normalize.css v3.0.0 | MIT License | git.io/normalize | |
// 1. Set default font family to sans-serif. | |
// 2. Prevent iOS text size adjust after orientation change, without disabling | |
// user zoom. | |
html | |
font-family sans-serif | |
-ms-text-size-adjust 100% |
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
x-rem ($property, $value) | |
{$property} $value * $main-font-size | |
{$property} {$value}rem |
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
function moveCursorToEnd(el) { | |
if (typeof el.selectionStart == "number") { | |
el.selectionStart = el.selectionEnd = el.value.length; | |
} else if (typeof el.createTextRange != "undefined") { | |
el.focus(); | |
var range = el.createTextRange(); | |
range.collapse(false); | |
range.select(); | |
} | |
} |