├── LICENSE ├── README.md ├── mq.js └── mq.min.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alfred Xing 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### mq 2 | < 200 byte DOM manipulation. 3 | 4 | #### Usage 5 | 6 | Use a single dollar sign to get a single element (first match) by CSS selector: 7 | ```js 8 | var el = $('header nav'); 9 | ``` 10 | 11 | Use a double dollar sign to get a NodeList of all elements matching the CSS selector: 12 | ```js 13 | var items = $$('header nav li'); 14 | ``` 15 | 16 | Operate directly on NodeLists using Array's `forEach` and `map` functions: 17 | ```js 18 | var items = $$('header nav li'); 19 | items.forEach(function(el) { 20 | console.log(el.innerHTML); 21 | }); 22 | ``` 23 | 24 | On a single element, use any property or function you'd normally use on an Element, HTMLElement, etc. (`addEventListener`, `innerHTML`, `classList`, `offsetTop`). 25 | 26 | #### Browser support 27 | Hard to really say, since it depends on what native methods you end up using. But mq is expected to work quite well in IE 9+ and other modern browsers (Chrome, Firefox, Safari). Open up an issue or PR if you know of anything major that doesn't work as expected across browser! 28 | 29 | #### Drawbacks 30 | - No standardization of methods/outputs (we are relying on the unreliable fact that browsers will behave in the same way). 31 | - No shortcuts 32 | 33 | #### Benefits 34 | - Tiny size 35 | - Performance 36 | - 'Standard' JavaScript — survive without needing jQuery! 37 | -------------------------------------------------------------------------------- /mq.js: -------------------------------------------------------------------------------- 1 | var d = document, n = NodeList.prototype, a = Array.prototype; 2 | var $ = d.querySelector.bind(d); 3 | var $$ = d.querySelectorAll.bind(d); 4 | 5 | n.forEach = a.forEach; 6 | n.map = a.map; -------------------------------------------------------------------------------- /mq.min.js: -------------------------------------------------------------------------------- 1 | var d=document,n=NodeList.prototype,a=Array.prototype,$=d.querySelector.bind(d),$$=d.querySelectorAll.bind(d);n.forEach=a.forEach,n.map=a.map; --------------------------------------------------------------------------------