Skip to main content
2 of 2
added 299 characters in body
Tomalak
  • 339.4k
  • 68
  • 547
  • 635
//B//*[starts-with(normalize-space(), 'history')] 

looks like it would do what you intend.

It selects "any descendant element of <B> whose text content starts with 'history'".

Manual iteration to find further nodes is not typically necessary. XPath does that for you. If you must iterate for some other reason, use the context node . to select.

nodes.forEach(function (node) { var history = select(node, "./*[starts-with(.,'history')]"); }); 

If you are actually looking for "any text node..."

//B//text()[starts-with(normalize-space(), 'history')] 

Or "any element node that has no further child elements..."

//B//*[not(*) and starts-with(normalize-space(), 'history')] 
Tomalak
  • 339.4k
  • 68
  • 547
  • 635