Skip to content Skip to sidebar Skip to footer

Assign Src Of Image To A Variable Through JS In HTML

I want to assign content of the src tag of image to a variable on clicking on the image through JS: Eg- HTML
+ element + "' />"; } </script> </head> <body> <div id="img"> <img id="img1" src="image1.jpg" onclick="setImage(this.id)" > <img id="img2" src="image2.jpg" onclick="setImage(this.id)" > </div> <span id="source"></span> </body> </html>

Solution 2:

you can try this,

<img ng-src="{{myVar}}">

Post a Comment for "Assign Src Of Image To A Variable Through JS In HTML"