Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

JavaScript - How to pass a single quote to a document.evaluate?

I'm getting the following error ncaught DOMException: Failed to execute 'evaluate' on 'Document': The string '//div[contains(., 'Please tell us how much you'd like to put into your account,')]' is not a valid XPath expression. for this line:
var sec3 = document.evaluate("//div[contains(., 'Please tell us how much you\'d like to put into your account,')]", document, null, XPathResult.ANY_TYPE, null).iterateNext();

Open in new window

If I remove the single quote from the string I'm looking for, the error goes away. I tried escaping the single quote and URL encoding it and it still breaks. How do I keep the single quote in the string?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Thank you Julian!
You are welcome.