0

I want to know why JQuery .css method returns a default value when no style attribute is provided just like in example here

var r = $('#mmalam').css('display');   $('#result').html(r);

I made a simple div, didn't give it style attribute but still .css method is returning "display = block"

Furthermore is there any JQuery method that will return empty value when no style is provided to the element?

0

2 Answers 2

2

All browsers have a built in style-sheet which dictates how an element should be displayed. divs are block elements and hence have the default style for display set to block.

This answer should shed some more light.

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

3 Comments

Good one, can you please also suggest me any method name which will only provide element's style value and if its not given then the function return empty/null.
I'm not aware of any function that will provide what you're asking for. Since all elements have a default style associated with them, you will get some value when you check. What are you trying to achieve? Maybe we can suggest an alternative approach.
what I am trying is to convert the javascript statement "document.getElementById('someid').style.display" to jquery code $('#someid').css('display') while style attribute is given dynamically (and is not provided in this case), however exactly as per your answer browser stylesheet is intervening and .css is ving me display value of "inline" which I thought should be empty when style is not provided
0

It's because the default display value is block

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.