/ Published in: JavaScript
Use sample:
var inputTxt = getElementsByAttr('input', 'type', 'text');
var inputTxt = getElementsByAttr('input', 'type', 'text');
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getElementsByAttr(tag, attr, value){ var arrayEl = new Array(); var el = document.getElementsByTagName(tag); for(i=0, j=0; i<el.length; i++){ if(el[i].getAttribute(attr) == value){ arrayEl[j] = el[i]; j++; } } return arrayEl; }