Why can't this click event type the opacity value of the element?

Oct.09,2021

you get the inline style


because you do not set
window.getComputedStyle you can get the final calculated style


take a look at the print, but the data is empty, because
< div id= "fade-obj" style= "width:300px;height:300px;background:-sharp000" > < / div >
there is no opacityvalue set in style

because there are only inline styles on obj.style,
you should write

window.getComputedStyle(obj,null).getPropertyValue("opacity")

obj.style gets the declared object key value of the DOM element CSS style.
style can only get the specific value of the inline style, but the internal and external styles cannot get the specific value.
obj.style is readable and writable. When you read obj.style, before writing obj.style in JS code, you will get a null value.

Menu