I have an html code to download files like this:
<a class="wp-block-button__link has-background has-vivid-green-cyan-background-color" href="https://github.com/pbatard/rufus/releases/download/v3.5/rufus-3.5.exe" rel="nofollow noopener noreferrer">Download (Installer)</a>
<a class="wp-block-button__link has-background has-vivid-green-cyan-background-color" href="https://github.com/pbatard/rufus/releases/download/v3.5/rufus-3.5p.exe" rel="nofollow noopener noreferrer">Download (Portable)</a>
I want all the URLs in the class="wp-block-button__link tag to change like this:
<a class="wp-block-button__link has-background has-vivid-green-cyan-background-color" href="mydomain.com/get/?url=https://github.com/pbatard/rufus/releases/download/v3.5/rufus-3.5p.exe" rel="nofollow noopener noreferrer">Download (Portable)</a>
<a class="wp-block-button__link has-background has-vivid-green-cyan-background-color" href="mydomain.com/get/?url=https://github.com/pbatard/rufus/releases/download/v3.5/rufus-3.5.exe" rel="nofollow noopener noreferrer">Download (Installer)</a>
I am currently changing it using Javascript like this:
let a = document.querySelector('.wp-block-button__link');
a.href = "mydomain.com/get/?url=" + a.href
console.log(a.outerHTML)
The javascript code that I use now can only change one URL, I want to change all the URLs in the class="wp-block-button__link" tag.
How do I make the javascript code I use change all URLs in the tag class="wp-block-button__link", not just one URL?
document.querySelectorAlland loop through itdocument.querySelectorAll('.wp-block-button__link').forEach(a => { a.href = "mydomain.com/get/?url=" + a.href });