JavaScript implements a simple method to traverse all attributes of a DOM object. javascriptdom
This example describes how to use JavaScript to traverse all attributes of a DOM object. We will share this with you for your reference. The details are as follows:
HTML of the DOM object:
Copy codeThe Code is as follows: <button id = "btnToggleState" onclick = "toggleStateManagement ()"> Disable State Cookie </button>
1. traverse all attributes of a DOM object (full attributes, 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 by DOM objects in HTML tags.
$. Each ($ ('# btntogglestate') [0]. attributes, function (I, attrib) {alert (I + ":" + attrib. name + ":" + attrib. value );});
I hope this article will help you design JavaScript programs.