<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<ul>
<li><a href="#">A</a><span></span></li>
<li><a href="#">B</a><span></span></li>
<li><a href="#">C</a><span></span></li>
</ul>
</body>
</html>
/*jshint expr:true eqnull:true boss:true */
var compose = function() {
return [].reduce.call(arguments, function(f,g) {
return function() {
return f(g.apply(this, arguments));
};
});
};
var join = function(f,g) {
return function() {
var as = arguments;
return f.apply(this, as).concat(g.apply(this, as));
};
};
var dot = function(prop) {
return function(x) {
return x[prop];
};
};
var loop = function(prop) {
return function(x) {
var result = [];
while (x = x[prop]) {
result.push(x);
}
return result;
};
};
var $ = (function(doc) {
var toArray = function(x) {
if (!x.length || typeof x != 'object') {
return x;
}
return Array.prototype.slice.call(x);
};
var flatten = function(xs) {
return Array.prototype.concat.apply([], xs);
};
var unique = function(xs) {
return xs.filter(function(x, idx) {
return xs.indexOf(x) == idx;
});
};
var query = function(sel, el) {
return toArray((el||doc).querySelectorAll(sel));
};
function Dom(sel) {
this.el = query(sel);
this.first = this.el;
this.length = this.el.length;
}
function $(sel) {
return new Dom(sel);
}
Dom.prototype = {
_update: function(result) {
this.prev = this.el;
this.el = [].concat(result);
this.length = this.el.length;
return this;
},
get: function(idx) {
return idx == null ? this.el : this.el[idx];
},
map: function(f) {
var result = this.el.map(compose(toArray, f).bind(this));
return this._update(unique(flatten(result)));
},
filter: function(sel) {
var result = this.el.filter(function(x) {
return query(sel, x.parentNode).indexOf(x) > -1;
});
return this._update(flatten(result));
},
end: function() {
return this._update(this.first);
},
back: function() {
return this._update(this.prev);
},
eq: function(idx) {
return this._update(this.el[idx]);
}
};
return $;
}(document));
// Example:
// Use these functions with `map` to chain
// Or you can also add them as methods
var children = dot('children');
var parents = loop('parentNode');
var prevAll = loop('previousElementSibling');
var nextAll = loop('nextElementSibling');
var siblings = join(prevAll, nextAll);
var text = dot('textContent');
var els = $('li').map(parents).get();
console.log(els);
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |