javascript – Find elements by attribute regex


I get for processing all elements that have the data-lang attribute

$("[data-lang]").each(function(index, element) {

<script src=""></script>
<input id="shop-input" type="text" maxlength="100" data-lang-placeholder="Filter">
<div id="shop-refresh" class="slim-content-btn noselect" data-lang="shop_refresh"></div>

But I also have data-lang-tittle attributes and the like. How to capture them too, tried $("[^data-lang]") does not exit


Personally, in my opinion, the solution below is worse than if, nevertheless, we add classes to the elements, but here the author of the question has to decide:

$('*').filter(function() {
    for(var prop in $(this).data()) {
        if(prop.indexOf('lang') !== -1) {
            return true;

    return false;
}).css('color', 'red');
<script src=""></script>
<div data-lang="hello">One</div>
<div data-lang-new="hello">Two</div>
<div data-not-this="hello">Three</div>

PS my comment to the question (link to JSFiddle) contains an error, who noticed – that fellow =)

Scroll to Top