How to search for image using javascript?

0

I wrote code that looks for specific text on a page and contains positive if it does not update. But I wanted to improve the code and make it look for lines in the source code of the page to find a specific image like this

src="https://i.dstatic.com/images/glyphish/837-palette-selected.png"

$(document).ready(function(){setTimeout(function(){varLookFor="texto "; // procurar por
        if ($('body:contains("' + LookFor + '")').length > 0) {
            alert("Achou " + LookFor);
            return;
        } else {
            location.reload();
        }
    }, 2000); // troca pra aumentar o tempo
});
    
asked by anonymous 11.07.2016 / 20:20

1 answer

0

See if it helps you?

Anything goes on commenting below that we are adapting the code.

function verifica() {

  if ( $('img[src="https://i.dstatic.com/images/glyphish/837-palette-selected.png"]').length>0){console.log('Achou.Páradeprocurar');alert('Encontrou!');}else{console.log('Nãoachou.Procuranovamentedepoisdointervalodefinido');setTimeout(verifica,2000);}}$(function(){verifica();$('button').on('click',function(){$('body').append('<imgsrc="https://i.dstatic.com/images/glyphish/837-palette-selected.png">');
    
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<button>Adiciona Imagem</button>
    
11.07.2016 / 21:22