Gudron Swiss
Gudron Swiss

Reputation: 445

How to add properties to an object

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>

Upvotes: 0

Views: 161

Answers (1)

Juan Garcia
Juan Garcia

Reputation: 305

Try this approach

img_big.src = photos[i].img_src;
img_big.className = "highslide";
img_big.onclick = function() { return hs.expand(this); }

Upvotes: 1

Related Questions