1

Consider following snipped code:

<div id="sample">
 <div es-value="true" />
 .....
 <span es-change="false" />
</div>

How can I get all elements that have attribute that it's name begins with "es-"?

AKZ
  • 856
  • 2
  • 12
  • 30
  • possible duplicate of [Find HTML based on partial attribute](http://stackoverflow.com/questions/12199008/find-html-based-on-partial-attribute) The accepted answer is only related to `data-` attributes, but the other answer is more generic. – James Montagne Apr 22 '14 at 17:41
  • 1
    Is there a specific reason you don't use the standard `data-` attributes? – 1andsock Apr 22 '14 at 17:44

2 Answers2

1

UPDATED

var test = $("div").filter(function() {
    var attr = this.attributes;
    for (var i=0; i<attr.length; i++) {
        if (attr[i].name.substr(0, 3) === "es-") {
            return true;
        }
    }
    return false;
});

console.log(test);

DEMO

sdespont
  • 13,915
  • 9
  • 56
  • 97
0

I didn't test it but this should work:

jQuery.expr[':'].contains = function (a, i, m) {
var elementList = [];
    $.each(jQuery(a).attr(),function(index,attribute)
{
if(attribute.toUpperCase().indexOf(m[3].toUpperCase()) >= 0)
{
elementList.push(attribute);
}

});
return elementList;
};

$.find('div:contains(''es-'')');
Bura Chuhadar
  • 3,653
  • 1
  • 14
  • 17