I have:

<A href="ссылка1/что/нибудь/значение11111" src="ссылка2/что/нибудь/значение22222" </A> 

It is necessary that in the "value 11111" 11111 is replaced with a random given number "from - to" And in "the value 22222" is replaced by 22222 with another specified number "from - to"

    1 answer 1

     function rand(max, min = 0) { return Math.floor(Math.random() * (max - min + 1)) + min; } // находим нужную ссылку const link = document.querySelector('a'); // выбираем значение ссылки const href = link.href; // или можно так //const href = link.getAttribute('href'); // декодируем кириллические символы const decodedHref = decodeURIComponent(link.href); // заменяем последние цифры в строке const replacedHref = decodedHref.replace(/\d+$/, rand(999999)); link.href = replacedHref; // можно так //link.setAttribute('href', replacedHref); 
     <A href="ссылка1/что/нибудь/значение11111" src="ссылка2/что/нибудь/значение22222">AAA </A> 

    • one
      I'm wildly sorry, but what about the src attribute in the tag A ? - Air
    • He displays a picture of the link and there <IMG in front of him, stela accidentally with: - Dimitri
    • Well, fix it ... Click the править button for an issue ... - Air
    • @vihtor can you tell where exactly to insert the code and how, for this to work, I’m generally 0 ... - Dimitri
    • This code must be inserted into the html-file, which contains the link itself. Below this link you need to add <script></script> , and insert the above code between them. But this code will only work for one, the first link found - vihtor