Get all Attributes from a HTML element with Javascript/jQuery

后端 未结 17 2118
时光说笑
时光说笑 2020-11-22 05:07

I want to put all attributes in a Html element into an array: like i have a jQuery Object, whichs html looks like this:



        
17条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 05:30

    Simple:

    var element = $("span[name='test']");
    $(element[0].attributes).each(function() {
    console.log(this.nodeName+':'+this.nodeValue);});
    

提交回复
热议问题