Take the 2-minute tour ×

When using this code:

var img = $("<img />").attr('src', 'devices/images/'+phoneid+'.png')
   .load(function() {
     alert('broken image!');
   } else {

It loads the image fine into

<div id="deviceimage"></div>

but won't apply css styling. Nor does it if I put it into

<img id="deviceimage"/>.
share|improve this question
The css should be applied regardless, it's probably getting overridden by some other styles. Did you inspect it in firebug or web inspector to see if the styles are getting overridden ? –  aziz punjani Nov 25 '11 at 23:25
@Interstellar_Coder Is this the only way? I have quite a lot of elements and properties and I can imagine it getting quite messy. Ah you've changed what you said, I shall inspect it now. –  Supertod Nov 25 '11 at 23:26
Can you post your CSS? –  sicks Nov 25 '11 at 23:27
Yeah, what does your CSS look like? The second way won't work because you can't nest img elements. In the first way, you need to address the image like so: #deviceimage img –  Pekka 웃 Nov 25 '11 at 23:30
Ah #deviceimage img did the trick, thanks for your help. –  Supertod Nov 25 '11 at 23:33
add comment


Your Answer



Browse other questions tagged or ask your own question.