Tuesday, September 18, 2012

How to get CSS class property value in javascirpt


Hello all,
Recently I working with javascript and css and for show and hide some element on base of css class's value.
I try  document.getElementById('elementId').style.display but it's failed because it's work only with inline style.

so I got below javascript code for get value of display property of css class in javascript.

   var elementObj = document.getElementById('elementId');
   var displayType= window.getComputedStyle(elementObj, null).getPropertyValue('display');
    alert(displayType);

displayType is the one of the value from inline,none or block.