I am doing an images gallery in JavaScript and I have a problem adding properties to my img
object.
Here is my code:
img_big.src = photos[i].img_src;
img_big.className = "highslide";
img_big.onclick = "return hs.expand(this)";
My problem is in the last line. How can I add properties to objects in a for
loop before pushing them into an array?
The object should has these properties:
<a href="path" class="highslide" onclick="return hs.expand(this)">
<img src="path" alt="Highslide JS" title="Click to enlarge" /></a>
Try this approach
img_big.src = photos[i].img_src;
img_big.className = "highslide";
img_big.onclick = function() { return hs.expand(this); }
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.