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.
<!-- 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>

Open in new window


Thanks!
894359Asked:
Who is Participating?
 
Steve BinkCommented:
If you are targeting a class, try using getElementsByClassName instead.  Note that you'll be receiving an array back, not a single element, so you'll need to iterate it to do your work.  The doc page has some relevant examples for you.
0
 
Steve BinkCommented:
This isn't possible with CSS.

With Javascript, you can use document.getElementById() to target the parent container.  Then get that element's innerText property to search for your text:
<script>
  var my_element = document.getElementById('main');
  if (my_element.innerText.search('We regret we cannot open the account you requested') > -1) {
    // text is found
  }
  else {
    // text is not found
  }
</script>

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
0
 
894359Author Commented:
Just realized main is a class and NOT an ID! :0)
0
 
894359Author Commented:
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) {} 

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.