Friday, August 3, 2012

Never used Computed Style in JS to check CSS. I see now its relevance. I can't believe that's never come up til now.

I had a JS function that checked the CSS of a DIV to see if its display was set to 'none'. Well, as many times as I've used JS to manipulate the DOM and CSS, I guess it had never come up where I was checking a style's value in a style sheet (embedded or external). I just couldn't get it to work unless I set the style inline or used JS to set the style first.
According to Stephen Stchur...

"Trying to retrieve the a css style property via javascript will only work when that style property has previously been set via javascript OR when that style property was defined inline by using the style attribute in (X)HTML. Now this doesn't do you much good if you haven't first set said css property in javascript (and I certianly hope no one is using inline css styles), and you still want to retrieve it via javascript."

The helpful folks at came to my rescue in a matter of minutes. That's where I found the link to Mr. Stchur's blog, among the other approaches to my question.

No comments:

Post a Comment