2

I have an element with display property set to none. I want to use javascript to return this display property. The code I'm using returns nothing or NULL when it should return "none". This is the code i'm using:

element CSS

.element
{
display:none;
}

javascript

function get_display_status()
{


    var element = document.getElementById('elementID');
    var status = element.style.display;

    document.write(status);
}

Result: Current status: ""

Image : http://gyazo.com/f662fd257602e973ca329a25314fb6ab

Any workarounds to this? Thanks

1 Answer 1

1

What you're getting is the elements inline style, what you want is its computed style, try

var status =  document.defaultView.getComputedStyle(element, null).display;
Sign up to request clarification or add additional context in comments.

2 Comments

Works 100%. Will select your answer, what exactly is the elements inline style?
That's when the element has a style attribute or you set the style like element. style.property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.