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

前端 未结 4 1023
南方客
南方客 2021-01-19 14:27

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

4条回答
  •  囚心锁ツ
    2021-01-19 15:13

    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/

提交回复
热议问题