Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  100] [ 7]  / answers: 1 / hits: 59502  / 5 Years ago, tue, march 12, 2019, 12:00:00

I have big html document with various images with href and src.



I want to declare their href and src so as to change only their var values. something like...





<script>
var imagehref = www.url.com;
var imagesrc = www.url.com/img.pg;
</script>

HTML Part:

<html>
<a href=imagehref><img src=imagesrc /> </a>
</html>





What is the correct syntax/way to do it?


More From » html

 Answers
57

You can't do it in this way, you have to set href and src directly from the js script. Here's an example:





<html>
<body>
<a id=dynamicLink href=><img id=dynamicImg src= /> </a>
</body>
<script>
var link = document.getElementById('dynamicLink');
link.href = http://www.url.com
var img = document.getElementById('dynamicImg');
img.src = http://www.url.com/img.png
</script>
</html>




[#52436] Thursday, March 7, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pierre

Total Points: 716
Total Questions: 128
Total Answers: 102

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
;