javascript - Select elements which start with "data-" -


how can select plan javascript or jquery every element has attribute starts "data-"?

i've tried

 $("[data-*"]) 

but doesn't work.

here non-jquery function need:

function getalldataelements() {     //get dom elements     var elements = document.getelementsbytagname("*");     //array store matches     var matches = [];     //loop each element     (var = 0; < elements.length; i++) {         var element = elements[i];         //get attributes element , loop them         var attributes = element.attributes;         (var j = 0; j < attributes.length; j++) {             //get name of attribute             var attr = attributes.item(j).nodename;             //check if attibute name starts "data-"             if (attr.indexof("data-") == 0) {                 matches.push(element); //add matches             }         }     }     return matches; //return results } 

which can used so:

var results = getalldataelements();  results.foreach(function (i) {     i.style.color = "#ff0000"; }); 

here working example


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -