jquery-on

0.1.8 • Public • Published

jquery-on

a jquery extend function '$.on' for all eventListener

Usage

  • run npm install jquery-on --save or download jquery.on.min.js
  • include jquery.js and jquery.on.min.js in your html file

Example

  • html
<div id="a">aaaaaaa</div>
<input id="b" placeholder="b">
<div class="ul" id="ul">
  <span class="li">1</span>
  <span class="li">2</span>
</div>
  • javascript
$.on({
  window: {
    scroll: function(event) {
      console.log('window scroll');
    }
  },
  '#a': {
    click: function(event) {
      console.log('a click');
    },
    dblclick: function(event) {
      console.log('a dblclick');
    }
  },
  '#b': {
    'input change': function(event) {
      console.log('b input or change');
    }
  },
  '.li': {
    parent: '#ul', // Event Delegation
    click: function(event) {
      console.log('li click');
    }
  }
});

Explain

  • All selectors and event just pass to $.fn.on function;
  • Read the souce file and give me some advices;

Package Sidebar

Install

npm i jquery-on

Weekly Downloads

0

Version

0.1.8

License

MIT

Last publish

Collaborators

  • rayman-v