attr-binder
v0.3.1
Published
Bind functions to attributes
Downloads
83
Readme
binder
A micro-library for binding functions to attributes in the dom. No dependencies. IE8+.
$ npm install attr-binder
var bind = require('binder')
bind(attribute, fn), bind(attribute, starting_node, fn)
Bind a DOM attribute to a function, passing in the attribute's value. The function is passed the node, the attribute value, and the attribute name.
For example, we have a "Post Comment" button that shows a sign-in modal or a comment modal depending on whether the user is signed in.
<p markdown>**This will get turned into markdown using marked.js**</p>
// Automatically render markdown
bind('markdown', function(node) {
node.innerHTML = marked(node.innerHTML)
})