0

Hi I am using angularjs to get a css property value but it is coming back undefined. Here is the code I am using:

var test = angular(document.querySelector('.mobile-menu')).attr('display');

This code is inside a directive.

2

1 Answer 1

1

I had found that even if your css class contains display your test var will be empty. you need to define it inside the style attribute of the element

<div class="mobile-menu" style="display: block"></div>

Javascript:

var test = angular.element(document.querySelector('.mobile-menu')).css('display');
alert(test);

JSFiddle: http://jsfiddle.net/AQtc8/

remove the style attribute from the div and test will be empty.

Sign up to request clarification or add additional context in comments.

Comments

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.