#1108 new
Marek Pepke

Enhanced Element.setOpacity and Element.getOpacity

Reported by Marek Pepke | August 3rd, 2010 @ 01:28 AM

Now it relates on property opacity. It doesn't work on IE and older versions of Firefox and Safari. SetOpacity could look like this:

Element.setOpacity = function (value) {

if (value > 1)
    value = 1;
if (value < 0.00001)
    value = 0;
try {
    this.filters.alpha.style = 0;
    this.filters.alpha.opacity = Math.round(100 * value);
} catch (e) { }
try {
    this.opacity = value;
} catch (e) { }
try {
    this.MozOpacity = value;
} catch (e) { }
try {
    this.KhtmlOpacity = value;
} catch (e) { }
return this;


GetOpacity colud be also related to other css properties.

Comments and changes to this ticket

  • Shellster

    Shellster June 3rd, 2011 @ 09:02 PM

    On a related note, IE8 breaks the alpha filter functionality without correctly implementing opacity. Here's my set opacity function which I believe should be added to setOpacity which already uses the prototype functionality when possible. It should be easy to modify for prototype. If you want me to submit a proper patch of setOpacity, and get Opacity, I'd be more than happy to do it. Can you at least provide a reason for why this isn't implemented already, if there is a reason for it? I'd like to know what problems I might not be aware of, as this seems to work flawlessly for my current needs.:

    _setOpacity: function(tid, opacity)

    if (typeof($(tid).style.opacity) == 'undefined')
        opacity *= 100;
                '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + opacity + ')',
                'filter': 'alpha(opacity=' + opacity + ')'


Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket