简体   繁体   中英

How can i have global alt tags in JavaScript

I have realy many many images. All images have alt tag something like alt="img1"...

Is there any change hold value of the tag in variable? Something like

<script>
    const altVariable="img";
</script>

and then in HTML use this variable like alt="<script>altVariable</script>" ?

I now the line above is bull**** and doesnt works like this.

You can do that by javascript , if you want to set all images with the same alt.

const altVariable="img";
document.querySelectorAll('img').forEach(img => img.alt = altVariable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM