On Github b1lly / fedemo
Created by Billy Bastardi / @wabism
Wat is dat?
e.g.: div, p, form, h1, h2, h3, ul, ol
/* CSS */
.parent-wrap {
width: 500px;
}
.child-block-element {
height: 200px;
}
<!-- HTML -->
<div class="parent-wrap">
<div class="child-block-element">
This is my content
</div>
</div>
e.g.: span, a, input, button
/* CSS */
.my-text {
text-decoration: underline;
}
<!-- HTML --> <p> This is a string of <span class="my-text">text</span> and we have a bunch of text in it. </p>
/* CSS */
#nav li {
display: inline-block;
height: 25px;
width: 125px;
padding: 10px;
}
<!-- HTML --> <ul id="nav"> <li>Home</li> <li>Location CMS</li> <li>Listings</li> <li>Social</li> <li>Analytics</li> </ul>
<!-- HTML --> <div id="box">This is a box</div> <div id="second-box">This is my second box</div> <p> This is a string of <span class="my-text">text</span> and we have a bunch of <span class="my-text">text</span> in it. </p>
/* CSS */
#second-box {
position: relative;
top: -10px;
left: 50px;
}
<!-- HTML --> <div id="box">This is a box</div> <div id="second-box">This is my second box</div>
/* CSS */
#box {
position: relative;
}
#second-box {
position: absolute;
bottom: 100px;
left: 50px;
}
<!-- HTML --> <div id="box"> This is a containing box <div id="second-box">This is my absolute box</div> </div>
/* CSS */
#second-box {
position: fixed;
height: 100px;
bottom: 100px;
left: 50px;
}
<!-- HTML --> <div id="box"> This is a containing box <div id="second-box">This is my fixed box</div> </div>
// Javascript
var myArr = ['this', 'is', 'my', 'array'];
myArr.join(' '); // returns 'this is my array'
myArr.pop(); // returns 'array' and mutates myArry = ['this', 'is', 'my']
myArr.push('list'); // mutates myArr = ['this', 'is', 'my', 'list']
myArray[0]; // returns 'this'
myArray['0']; // returns 'this'
<!-- HTML --> <div class="my-node">This is my node</div> <div class="my-node">This is my other node</div>
// Javascript
var myNodes = document.getElementsByClassName('my-node');
// myNodes = [HTMLElement, HTMLElement]
myNodes[0].onclick = function() {
alert('Ouch, that hurts!');
}
myNodes[1].onclick = function() {
alert('Ouch, that hurts!');
}
// Javascript
var x = 1;
function foo() {
for (var i = 0; i < 10; i ++) {
var y = i;
}
return x + y;
}
foo();
function foo() {
alert('hey, this works!');
}
foo();
var foo = function() {
alert('hey, this works?');
}
// Global scope
(function() {
// This is my local scope
var d = document.getElementById('my-node');
d.onclick = function() {
alert('Ouch, that hurts!');
};
})();
<div id="wrap"> <div class="my-node">This is my node</div> <div class="my-node">This is my node</div> </div>
$('.my-node'); // jQuery('.my-node')
// Returns an 'array-like' object with a bunch of jQuery props/methos
// [HTMLElement, HTMLElement]
{
on: function(event, fn) {
// Interact with "this collection" and do stuff
},
length: 3
}
<div id="wrap"> <div class="my-node">My name is Billy</div> <div class="my-node">I am a F.E. Ninja</div> </div> <div class="my-node">Other data</div>
// Find the node with my name and get the contents
$('#wrap').find('.my-node').css('background-color', 'red');
$('.my-node').closest('#wrap'); // find the closest parent with this id
<script type="text/template" id="js-user-tmpl">
<div class="user-wrap">
<div class="name">Billy Bastardi</div>
<div class="email">billy@yext.com</div>
</div>
</script>
var $tmpl = $('#js-user-tmpl');
function createUser(name, email) {
var $newUser = $tmpl.clone();
$newUser.find('.name').text(name);
$newUser.find('.email').text(email);
$('body').append($newUser.html());
};
createUser('John Smith', 'johnsmith@yext.com');
createUser('Jane Doe', 'janedoe@yext.com');
<div class="my-node">This is my node</div> <div class="my-node">This is my other node</div>
$('.my-node').on('click', function() {
alert('Ouch, that hurts');
});
<div id="add-user"> <input type="text" name="name" class="js-input-name"> <input type="text" name="email" class="js-input-email"> <button class="js-add-user-btn">Post it!</button> </div>
$('.js-add-user-btn').on('click', function() {
var msg = $('.js-input-name').val(),
author = $('.js-input-email').val();
createUser(msg, author);
});