views:

18

answers:

1

I have some js code which generates an image-tag like this:

main_pic_div.innerHTML ="<img src='"+path_big_image+"?"+Math.random();"' class='shadow'>";

But the class wont be applied to it...

Here is what you get when you 'view source' in firefox:

    <img src="ad_images/Bilar/441372870_1.jpg?0.6932381395385144"/>

The class isn't even there, why?

I have tried with all kinds of quotes!

Thanks

+4  A: 

I think it should be

main_pic_div.innerHTML ="<img src='"+path_big_image+"?"+Math.random()+"' class='shadow'>";

(You left out the plus sign after Math.random())

danben
nope, doesn't work either, generates the same source as above...
Camran
Really? It makes sense that that error would cause the problem that you were getting, because the part of the string with the class would be interpreted separately from the assignment statement. I will of course defer to you because you have the code but...are you sure?
danben
Oh! My mistake. See my edit. I removed the semicolon, too.
danben
Wonderful! Thank you danben!
Camran
It would be even better to use a timestamp instead of a random number: `Date.parse(new Date())`
Mathias Bynens
@Mathias Bynens: A timestamp would have a greater chance of collisions than a random number.
Asaph