var elems = document.querySelectorAll("[src$='.gif'], [href$='.gif']"); Array.prototype.forEach.call(elems, function( val ){ val.???? = ..........; });