Iterating over element attributes with jQuery

前端 未结 8 976
独厮守ぢ
独厮守ぢ 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条回答
  •  长情又很酷
    2020-11-30 05:48

    How about?

    $(xml).find('item').each(function() {
      var attributes = $(this)[0].attributes;
      for (attribute in attributes) {
        // Do something with each attribute...
      }
    });
    

提交回复
热议问题