tags:

views:

464

answers:

5

Is it possible to set the src attribute value in CSS. At present what i am doing is:-

<img src="pathTo/myImage.jpg"/>

and i want it to be something like this

<img class="myClass" />

also, i don't want to use the background or background-image: property.

+4  A: 

No you can't set the image src attribute via CSS. The closest you can get is, as you say, background or background-image. I wouldn't recommend doing that anyway as it would be somewhat illogical.

cletus
A: 

No, if you don't want ot use the backgroundproperty trick, you can't. You'll have to use JavaScript for instance to change the image.

gregseth
+1  A: 

If you don't want to set a background property then you can't set the src attribute of an image using only CSS.

Alternatively you can use JavaScript to do such a thing.

Guillaume Flandre
+3  A: 

As far as I am aware of, YOU CANNOT. CSS is about style and image's src is content.

NawaMan
A: 

Using CSS, it can't be done. But, if you are using JQuery, something like this will do the trick:

$("img.myClass").attr("src", "http://somwhere");
Veera