The example in this article describes the implementation method of traversing all attributes of DOM objects in JavaScript. Share it with everyone for your reference, the details are as follows:
HTML of DOM object:
1. Traverse all attributes of the DOM object (all attributes will be traversed regardless of whether they are set in the HTML tag)
var obj=document.getElementById("btnToggleState") var s=""; for(var elem in obj) s+=elem+"\n"; alert(s);
2. Traverse the attributes set in the HTML tag of the DOM object
$.each($('#btnToggleState')[0].attributes,function(i,attrib){ alert(i+":"+attrib.name+":"+attrib.value); });
I hope this article will be helpful to everyone in JavaScript programming.