admin管理员组文章数量:1405581
I've two divs: the div "#Stage" is display="block" and from time to time "display:none". Depending on this I'll appear my second div "#case", default is display="none".
So I tried these two ways:
if ($('#Stage').css('display') == 'none') {
$('#case').css('display','block')
} // added display:none; to my css file at #case
if ($('#Stage').css('display') == 'none'){
$('#case').show()
} else if ($('#Stage').css('display') != 'none'){
$('#case').hide()
}
But both of these methods doesn't work, means the #case div is always on display:none. Does anyone know how to solve it?
THanks
I've two divs: the div "#Stage" is display="block" and from time to time "display:none". Depending on this I'll appear my second div "#case", default is display="none".
So I tried these two ways:
if ($('#Stage').css('display') == 'none') {
$('#case').css('display','block')
} // added display:none; to my css file at #case
if ($('#Stage').css('display') == 'none'){
$('#case').show()
} else if ($('#Stage').css('display') != 'none'){
$('#case').hide()
}
But both of these methods doesn't work, means the #case div is always on display:none. Does anyone know how to solve it?
THanks
Share Improve this question edited Feb 11, 2013 at 9:28 axel.michel 5,7741 gold badge17 silver badges25 bronze badges asked Feb 11, 2013 at 9:26 user2060787user2060787 1- 1 Can you please add html to the question? – Adil Commented Feb 11, 2013 at 9:40
3 Answers
Reset to default 7I would use :visible to check if the element is shown or not and use show() and hide() method.
if ($('#Stage').is(':visible'))
$('#case').show();
else
$('#case').hide();
or
if ($('#Stage:visible').length)
$('#case').show();
else
$('#case').hide();
It could possibly because you're using display:none
in the CSS file, and it's taking precedence. Try doing it inline on #case
and seeing if that works.
Thanks for your help. My two solutions and the first from Adil was working. It was an ordering conflict with Adobe Edge - edgeActions.js.
本文标签: javascriptchange displaynone with jquery with ifelseStack Overflow
版权声明:本文标题:javascript - change display:none with jquery with if-else - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744298692a2599471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论