General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Scripting: Something like getElementsByTagName, for specific attribute & value?
-
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 14 years agoHi,
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?
Thanks,
Russ
Derek Read March 10, 2009 at 9:11 pm
Reply to: Scripting: Something like getElementsByTagName, for specific attribute & value?
March 10, 2009 at 9:11 pmThe 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:
[code]
// XMetaL Script Language JSCRIPT:
var parasWithId = ActiveDocument.getNodesByXPath(“//p[@id]”);
Application.Alert(parasWithId.length);[/code]This API returns a DOMNodeList of DOMElement objects. For more information refer to the XMetaL Developer Programmers Guide.
-
AuthorPosts
- You must be logged in to reply to this topic.