Home > Web Front-end > JS Tutorial > body text

JavaScript implementation method of simply traversing all attributes of DOM objects_javascript skills

WBOY
Release: 2016-05-16 15:35:56
Original
1273 people have browsed it

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:

Copy code The code is as follows:

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);
Copy after login

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);
});
Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template