javascript - How to get all elements with a specified href attribute -


let i've elements href=/href_value/attribute. how elemenets such href attribute has href_value value?

heres version work in old , new browsers seeing if queryselectorall supported

you can use calling getelementsbyattribute(attribute, value)

here fiddle: http://jsfiddle.net/ghrqv/

var getelementsbyattribute = function(attr, value) {     if ('queryselectorall' in document) {         return document.queryselectorall( "["+attr+"="+value+"]" )        } else {         var els = document.getelementsbytagname("*"),             result = []          (var i=0, _len=els.length; < _len; i++) {             var el = els[i]              if (el.hasattribute(attr)) {                 if (el.getattribute(attr) === value) result.push(el)             }         }          return result     } } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -