Reputation: 11825
How can I check a value (from the CSS tag) with jQuery?
CSS
#my_div { display:none; }
JS
$(document).ready(function()
{
if($('#my_div').is(':hidden'))
{
$('body').append('HIDDEN');
}
else
{
$('body').append('VISIBLE');
}
}
This did not work. Hope somebody can help me.
Example: http://jsfiddle.net/9fSM6/
Upvotes: 1
Views: 7046
Reputation: 11658
You just could use css
function. It return value of given css property:
$('#my_div').css('display')
Upvotes: 2
Reputation: 3402
You are missing the closing parenthesis from ready
: );
Also, put a <div id="my_div"></div>
in your code, otherwise it will be handled as 'visible', because you have no 'my_div' element, so it is also not hidden.
Updated code: http://jsfiddle.net/ug6Dv/
Re-updated code: http://jsfiddle.net/PcmJW/
Upvotes: 3
Reputation: 66389
Worked just fine for me when I added such div
element: http://jsfiddle.net/9fSM6/3/
When you don't have any element, the is()
will always return undefined
so the else
part will always be triggered.
Upvotes: 2