Using CSS can often be more efficient than relying on Javascript for styling purposes. If you can achieve your desired effect with CSS alone, it is preferable to avoid unnecessary scripting.
CSS specificity rules dictate that inline styles and HTML attributes take precedence over External or Embedded CSS. However, while inline CSS can be useful in certain project scenarios, it is generally not considered best practice.
Optimal CSS opacity implementation:
img {
opacity: 0.4;
filter: alpha(opacity=40); /* For compatibility with IE8 and earlier */
}
https://css-tricks.com/almanac/properties/o/opacity/
img {
/* Preferred approach for IE 8 & 9 (more valid) */
/* ...though not essential as filter also functions */
/* should precede filter */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; // IE8
/* This method is effective in IE versions 5-7 as well */
filter: alpha(opacity=50); // IE 5-7
/* Modern Browser support */
opacity: 0.5;
}