How do I get the opacity of an element using Javascript?
问题 If I have: #em { opacity:0.5; } How do I get #em 's opacity using javascript ? :D I've got troubles with the following (it returns nothing): return document.getElementById("em").style.opacity; 回答1: Setting a CSS value in a stylesheet is not the same as setting it through the style property. You need to look at the getComputedStyle method to obtain this (and also currentStyle for older IE). 回答2: var em = document.getElementById("em"); var temp = window.getComputedStyle(em).getPropertyValue(