https://github.com/jayrbolton/binder
Bind functions to DOM attributes.
https://github.com/jayrbolton/binder
Last synced: 3 months ago
JSON representation
Bind functions to DOM attributes.
- Host: GitHub
- URL: https://github.com/jayrbolton/binder
- Owner: jayrbolton
- Created: 2014-02-14T00:13:34.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-01-27T19:05:49.000Z (over 9 years ago)
- Last Synced: 2025-01-31T20:55:59.468Z (3 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# binder
A micro-library for binding functions to attributes in the dom. No dependencies. IE8+.
```sh
$ npm install attr-binder
``````js
var bind = require('binder')
```#### bind(attribute, fn), bind(attribute, parentNode, 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.```html
**This will get turned into markdown using marked.js**
``````js
// Automatically render markdown
bind('markdown', function(node) {
node.innerHTML = marked(node.innerHTML)
})
```You can scope the bindings beneath a parent element
```js
bind('markdown', document.querySelector('.content'), fn)
// only binds to elements that are children of .content
```