I am trying to select an element containing 1'000 g
using document.evaluate(). The issue is the apostrophe. I tried to use u0027
, ''
, '
, \'
and '
, but those either trigger invalid xpath expression errors or return no elements.
const items1 = document.evaluate(
"//p[contains(normalize-space(.), '1000u00a0g')]",
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
console.log("item1", items1.snapshotItem(0).textContent);
const items2 = document.evaluate(
"//p[contains(normalize-space(.), '1'000u00a0g')]",
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
console.log("item2", items2.snapshotItem(0).textContent);
<p>1000 g</p>
<p>1'000 g</p>
What is the correct way to select an element containing an apostrophe using an xpath expression in document.evaluate()?