Iterating over element attributes with jQuery

前端 未结 8 981
独厮守ぢ
独厮守ぢ 2020-11-30 05:38

I know individual attributes can be retrieved with the attr() method, but I\'m trying to iterate over all of the attributes for an element. Fo

8条回答
  •  旧时难觅i
    2020-11-30 06:11

    created this generic function that allows to look-in attributes as well as innearHtml:

    function findByAll(toLookFor, lookInText) { 
        return $('*').filter(function() { 
            return Array.prototype.some.call(this.attributes, function(attr) {
                return attr.value.indexOf(toLookFor) >= 0; 
            }) || (lookInText && $(this).text().indexOf(toLookFor) >= 0); 
        }); 
    }
    

提交回复
热议问题