Programmer's Guide > Programming and Scripting Techniques > Basic Document Manipulation Using the DOM and AOM > Traversing a Document Using the DOM and AOM > Using getElementsByAttribute
  
Using getElementsByAttribute
The previous example could be improved by using the AElement.getElementsByAttribute method. (The AOM AElement interface extends the W3C DOM Element interface.) Doing so will return only those tags from the document that have the role attribute set to bold. The value on all of the tags can then be changed from bold to italic without having to test every <emphasis> tag in the document.
The getElementsByAttribute method takes three arguments: name, value, and selector. If selector is set to 1 (one), the search will return all nodes that match both name and value. If selector is set to 0 (zero), all nodes matching name, regardless of their value, are returned.
var doc = Application.activeDocument;
var tags = doc.getElementsByAttribute("role", "bold", 1);
for (i=0; i < tags.length; i++) {
tags.item(i).setAttribute("role", "italic");
}