Transparent image - is this possible in JS?

Is it possible to set the transparency of any image in javascript? And how can I do this?

+6
javascript image transparency
source share
2 answers

When using simple javascript, this should work:

function SetOpacity( imageid, opacity ) { var s= document.getElementById(imageid).style; s.opacity = ( opacity / 100 ); s.MozOpacity = ( opacity / 100 ); s.KhtmlOpacity = ( opacity / 100 ); s.filter = 'alpha(opacity=' + opacity + ')'; } 

Call: SetOpacity('myImg', 50); //Half transparent SetOpacity('myImg', 50); //Half transparent

Source here

+8
source share

Yes.

Using jQuery :

 $('#yourImageId').css('opacity', .5); 
+3
source share

All Articles