JavaScript Searching for a word on a page after an AJAX call searching word on web page

Here's a quick and programmatic way to determine whether the current HTML page contains a specific keyword:

function pageContains(str) {
    return document.body.innerHTML.toString().indexOf(str) > -1;
}

JSFiddle: https://jsfiddle.net/shj4LwqL/


Please be aware that the above code searches for the keyword in the page's body tag, so if you have your JavaScript in the page body, and your keyword is written as a string in your JavaScript, then you will get a false positive. If you want to search within a specific element instead, you can use the following variant:

function elementContains(el, str) {
    return el.innerHTML.toString().indexOf(str) > -1;
}
Answer:1

searches for only in content, not in tags and so on:

function searchInPage(val) {
    var allElements = document.getElementsByTagName('*');

    for(var i = 0; i < allElements.length; i++) {
        var node = allElements[i].firstChild;

        //Is it a text node?
        if(node !== null && node.nodeType === 3) {
            if(node.nodeValue == val) return true;
        }
    }
    return false;
}

untested it shows you the way to do it.

Answer:2

This my code when click the button i want to display button dynamic id to the specific place by calling that id: this is my code: <span id="2" class="view-details">View Details</span> $( ...

This my code when click the button i want to display button dynamic id to the specific place by calling that id: this is my code: <span id="2" class="view-details">View Details</span> $( ...

  1. jquery append not working with html

I have a simple jQuery slider but cant get multiple instances of it to work on the page, I am sure its an easy fix but my brain is just not co-operating atm function testSlide() { var testAnim = ...

I have a simple jQuery slider but cant get multiple instances of it to work on the page, I am sure its an easy fix but my brain is just not co-operating atm function testSlide() { var testAnim = ...

  1. simple jquery slider free download
  2. simple jquery slider codepen
  3. simple jquery slider plugin
  4. simple jquery slider example with source code
  5. simple jquery slider with next previous buttons
  6. simple jquery slider
  7. simple jquery slider w3schools
  8. simple jquery slider code
  9. simple jquery slider jsfiddle
  10. simple jquery slider tutorial
  11. simple jquery slider with dot navigation
  12. simple jquery slider responsive
  13. simple jquery slider example
  14. simple jquery slider autoplay
  15. simple jquery slider with thumbnails
  16. simple jquery slider with bullets
  17. simple jquery slider download
  18. simple jquery slider code example
  19. simple jquery slider with controls
  20. simple jquery slider left to right

Today I was wondering what would be the swiftest method to provide a cycle-through array in TypeScript, as in: ['one', 'two', 'three'] where the next value after three would be one, and I thought ...

Today I was wondering what would be the swiftest method to provide a cycle-through array in TypeScript, as in: ['one', 'two', 'three'] where the next value after three would be one, and I thought ...

I’m working on a card game in JS. The player’s cards are dynamically displayed as elements inside a div of a set width. As cards are added to the player’s hand, I’m using right: % and z-index to shift ...

I’m working on a card game in JS. The player’s cards are dynamically displayed as elements inside a div of a set width. As cards are added to the player’s hand, I’m using right: % and z-index to shift ...