Jquery: function search if file name contains and replace

Asked

Viewed 23 times

-2

Function to replace src if it contains a word. Ex:

<li class"none">
    <img src="/img/aqui-pode-mudar-exemplo.png?v=123456" alt="Imagem">
</li>
Function to search in the "None" classes if the SRC contains "example" and replace. In case change all src.

Another possibility that can help me is a way to ignore the "? v=#####" after the extension:

$("img[src='/img/exemplo.png?v=#####']").attr('src', "/novapasta/img/novaimagem.png");

Example above does not work due to "?=#####".

  • your question is a little confusing, put data that explains better, and tbm include javascript code than you have tried

  • NOTE: I cannot edit the HTML directly, only insert via <script>, and the cited classes ("None") whose image contains the cited src can be in random positions.

  • I couldn’t understand... what must be in the source to be found?

  • If a "src" of the <img> within <li> of certain classes has a certain word, then replace src with another. In the example above, the Given Class is "None" and the word that needs to be found in "src" is "example".

1 answer

0


That is the solution.

$('.none img[src*="exemplo"]').attr('src', 'novo/caminho/imagem.png');
<li class"none">
        <img src="/img/aqui-pode-mudar-exemplo.png?v=123456" alt="Imagem">
</li>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.