/kewjs

Kew is a lightweight alternative to jQuery selectors.

Primary LanguageJavaScript

KewJS

Lightweight alternative to jQuery selectors & basic utilities

⬇️ Download

Usage

Initialize kew.js

Include the library in your page

    <script src="path/to/kew.min.js"></script>

1. Document ready

    $kew().ready(function(){
        // code to be executed after document has loaded
    });

2. $kew() Selector

You can select an element by using a CSS type selection.

Examples
    $kew('div');
    $kew('.foo div');
    $kew('#foo.bar');

3. Utilities

each()
// Loops through all selected elements and executes function
$kew('#foo').each(function(el) {
    console.log(el.innerHTML);
})
attr()
// Adds an attribute to all selected elements
$kew('#foo').attr('data-custom', 'myValue');

// result: <div id="foo" data-custom="myValue"></div>
class()
// An alias of attr() - adds a class to an element
$kew('#foo').class('bar');

// result: <div id="foo" class="bar"></div>
remove()
// Removes selected elements from the document
$kew('#foo').remove();
add()
// Add a child element to a specified parent element
$kew('#foo').add('<p>bar</p>');