homepage Welcome to WebmasterWorld Guest from 107.22.141.14
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
setting CSS via JS
sssweb




msg:4394175
 10:10 pm on Dec 4, 2011 (gmt 0)

I can't get the following portion of my javascript to set CSS opacity:

<script language="JavaScript">
...
var trans = 0.5;
elementid.opacity = trans;
</script>

This doesn't work either:

document.getElementById("elementid").opacity = trans;

 

penders




msg:4394193
 11:21 pm on Dec 4, 2011 (gmt 0)

document.getElementById("elementid")
.style.opacity = trans;

You will also need to set the filter property if you intend to support IE8 and below...
document.getElementById("elementid").style.filter = 'alpha(opacity=' + trans*100 + ')';

sssweb




msg:4394367
 12:49 pm on Dec 5, 2011 (gmt 0)

Thanks penders, that was it.

Yes, I have the IE8 code too; that came with the script and was working fine, but I couldn't convert it for other browsers. It's in a slightly different format:

elementid.filters( "alpha" ).opacity = 50;

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved