MJ
asked on
Detect Phrase on a Web-page?
I'm trying to figure out how I can scrap/detect if the phrase "We regret we cannot open the account you requested." is on the page using CSS Selector and/or Javascript (jQuery is ok if that is the only option but want to avoid it if possible?). Below is an excerpt from the mark-up.
Thanks!
<!-- current page: offers -->
<div class="main">
<h3>Eligibility Results</h3><p>Thank you for your online application for an account at Bank of the West. We regret we cannot open the account you requested.<br/>
If you would like to discuss this application with Bank of the West, please contact us at:</p>
Thanks!
ASKER
Just realized main is a class and NOT an ID! :0)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
try{
var appDeclined = 0;
var myCollection = document.getElementsByClassName('main');
i = myCollection.length;
while(i--) {
if (myCollection[i].innerText.search('We regret we cannot open the account you requested') > -1) {
appDeclined = 1;
}
}
} catch(e) {}
With Javascript, you can use document.getElementById() to target the parent container. Then get that element's innerText property to search for your text:
Open in new window
https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search