0

I need to know the content of a class by using js. for example :-

<p style='visibility:hidden'>hello !</p>

if we wrote

alert(document.getElementsByTagName('P')[0].style.visibility)

it will returns "hidden" , BUT if we wrote

<p class='peter'>hello !</p>
<style>.peter{visibility:hidden}</style>

it will returns "". !!!!

peter hany
  • 43
  • 1
  • 9
  • 2
    Possible duplicate of [Get all computed style of an element](http://stackoverflow.com/questions/8625855/get-all-computed-style-of-an-element) – NineBerry Dec 11 '16 at 00:27

1 Answers1

0

elem.style refers to its HTML style attribute, not its computed style. So styles that are declared with a <style></style> tag or <link/ tag will be computed but they won't affect elem.style, as they are not the value of the elements style attribute. Only <sometag style="..."> would affect elem.style. To get computed style, try using window.getComputedStyle(elem).

Kyle Lin
  • 827
  • 8
  • 16