Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opacity and style undefined when accesing element in js but defined in css

With this fiddle http://jsfiddle.net/mungbeans/f2ne6/2/

why is the opacity undefined when accessed in js when its defined in the css?

I presume the answer is because the style is also undefined, why is that, does the style need adding somewhere explicitly before the opacity can be defined?

EDIT the lack of [] is a typo created as I copied from source to fiddle. The style/opacity problem still exits in the original code which is correct in that aspect.

like image 611
Gruntcakes Avatar asked Dec 20 '22 16:12

Gruntcakes


1 Answers

title.style.opacity

should be:

title[0].style.opacity

since getElementsByTagName returns a nodeList.

EDIT:

This still doesn't get the value. You'll need to do the following:

window.getComputedStyle(title[0]).opacity

https://developer.mozilla.org/en-US/docs/DOM/window.getComputedStyle?redirectlocale=en-US&redirectslug=DOM%3Awindow.getComputedStyle

DEMO: http://jsfiddle.net/f2ne6/12/

like image 179
Chase Avatar answered May 12 '23 11:05

Chase