General XMetaL Discussion
russurquhart1 March 10, 2009 at 3:57 pm
Scripting: Something like getElementsByTagName, for specific attribute & value?March 10, 2009 at 3:57 pmParticipants 0Replies 1Last Activity 13 years, 3 months ago
I am currently using getElementsByTagName to get a DOMnodelist. Is there a way to filter this list further with something like a getElementsByAttribVal(strAttrname, strVal)? I am currently looping though the list i get, to determine which nodes are to be worked on, but was just wondering if anyone had a better command to do this?
RussDerek Read March 10, 2009 at 9:11 pm
Reply to: Scripting: Something like getElementsByTagName, for specific attribute & value?March 10, 2009 at 9:11 pm
The API getNodesByXPath will allow you to return a list of element nodes that have specific attributes set. Here is an example that tells you how many
elements in your document have an id attribute value:
// XMetaL Script Language JSCRIPT:
var parasWithId = ActiveDocument.getNodesByXPath(“//p[@id]”);
This API returns a DOMNodeList of DOMElement objects. For more information refer to the XMetaL Developer Programmers Guide.
- You must be logged in to reply to this topic.