We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

szsk on 08/02/06


Tagged

javascript opacity DOM alpha


Versions (?)


Who likes this?

8 people have marked this snippet as a favorite

jonhenshaw
luman
meth
malag
Hirmine
vali29
SpinZ
gbot


setOpacity


Published in: JavaScript 


  1. function setOpacity( element, alpha ) {
  2. var style = element.style;
  3. if( style.MozOpacity != undefined ) { //Moz and older
  4. style.MozOpacity = alpha;
  5. }
  6. else if( style.filter != undefined ) { //IE
  7. style.filter = "alpha(opacity=0)";
  8. element.filters.alpha.opacity = ( alpha * 100 );
  9. }
  10. else if( style.opacity != undefined ) { //Opera
  11. style.opacity = alpha;
  12. }
  13. }

Report this snippet 

You need to login to post a comment.