JSFiddle - React, Tailwind, and code Playground

by Ronny

HTML

<div id="Content" data-ga="example report">Hello</div><div data-cacti="2834782">bla</div><div id="no">hmm</div>

JavaScript

Element.implement({
     getCustomAttributes: function(){
        var customAttributes = ['data-ga', 'data-cacti'],
            foundAttributes = [];
         customAttributes.each(function(attr){
            thisattr = this.get(attr);
            thisattr && foundAttributes.push(thisattr);
         }.bind(this));
        return foundAttributes;
     }
 });

console.log($('Content').getCustomAttributes());

/* / Single Element */

/* Regular approach */
var found2 = $H({});
$$('div').each(function(el){
    if(el.getCustomAttributes().length > 0)
        found2.include(el.get('html'), el.getCustomAttributes());
});

/* Type based approach */
Array.implement({
     getCustomAttributes: function(){
         var found = $H({});
         this.each(function(el){
             if ($type(el) == 'element' && el.getCustomAttributes().length > 0)
                 found.include(el.get('html'), el.getCustomAttributes());
         });
         return found;
     }
 });

console.log([$('Content'),2,'3',$('no')].getCustomAttributes());