All samples are using Ink.requireModules, please read how to use it at Ink.requireModules section

Ink.Dom.Selector namespace

Functions
Function name Description
.matches(selector, matches) Filters elements that match a CSS selector.
.matchesSelector(element, selector) Checks if an element matches a given selector
.select(selector, [context], [results]) Alias for the Sizzle selector engine

.matches(selector, matches) method

Filters elements that match a CSS selector.

Accepts

  • selector

    CSS selector to search for elements
  • matches

    Elements to be 'matched' with

Code

<div id="container">
    <div class="level_1">
        <ul>
            <li>A</li>
            <li class="active">B</li>
            <li>C</li>
        </ul>
    </div>
</div>
<script>
Ink.requireModules(['Ink.Dom.Selector_1'], function(InkSelector) {
    var aElms1 = InkSelector.matches('#container');
    var aMatches1 = InkSelector.matches('#container li.active', aElms1);
    Ink.log(aMatches1); 
    // [] 
    var aElms2 = InkSelector.matches('#container li');
    var aMatches2 = InkSelector.matches('#container li.active', aElms2);
    Ink.log(aMatches2);
    // [li.active]
});
</script>

.matchesSelector(element, selector) method

Checks if an element matches a given selector

Accepts

  • element

    Element to test
  • selector

    CSS selector to test the element with

Code

<div id="container">
    <div class="level_1">
        <ul>
            <li>A</li>
            <li class="active">B</li>
            <li>C</li>
        </ul>
    </div>
</div>
<script>
Ink.requireModules(['Ink.Dom.Selector_1'], function(InkSelector) {
    var aElms = InkSelector.select('#container li.active');
    var elm = aElms[0]; // <li class="active"> 

    InkSelector.matchesSelector(elm, '#container'); // false 
    InkSelector.matchesSelector(elm, 'ul'); // false 
    InkSelector.matchesSelector(elm, 'ul > li'); // true 
    InkSelector.matchesSelector(elm, 'li.foobar'); // false 
    InkSelector.matchesSelector(elm, 'li.active'); // true
    InkSelector.matchesSelector(elm, 'li'); // true
});
</script>

.select(selector, [context], [results]) method

Alias for the Sizzle selector engine

Accepts

  • selector

    CSS selector to search for elements
  • context

    By default the search is done in the document element. However, you can specify an element as search context
  • results

    By default this is considered an empty array. But if you want to merge it with other searches you did, pass their result array through here.

Code

<div id="container">
    <div class="level_1">
        <ul>
            <li>A</li>
            <li class="active">B</li>
            <li>C</li>
        </ul>
    </div>
</div>
<script>
Ink.requireModules(['Ink.Dom.Selector_1'], function(InkSelector) {
    var elms = InkSelector.select('#container li.active');
    Ink.log(elms);
    // [li.active]
});
</script>