Getting CSS containt using JS from <style> tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lagon666
    New Member
    • Jun 2009
    • 22

    Getting CSS containt using JS from <style> tag

    How can i get css contains of an element.
    When i use alert(document. getElementById( 'mydiv').style. opacity) it will return empty.

    Code:
    <style>
    #mydiv{
    background:#000000;
    opacity:0.4;
    }
    </style>
    
    <div id="mydiv">inner</div>
    Code:
    <script>
    function getOpacity(){
    alert(document.getElementById('mydiv').style.opacity); // it returns an empty message box
    }
    </script>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that depends on when you define and call the JS/CSS. though it could also be that you have to access those CSS with getComputedStyl e()

    Comment

    Working...