当 Div 可见时显示标题
我试图根据某些 DOM 元素在页面上是否可用/可见来显示两个标题之一。由于某种原因,它不起作用...这是到目前为止的现场演示。
我有以下代码:
$('h3.list_heading').css('display', 'none');
$('h3#error').css('display', 'none');
if ( $('div.availableNowListing').filter(':visible').length == 0) {
$('h3#error').css('display', 'block');
} else {
$('h3.list_heading').css('display', 'block');
}
目前,无论我选择什么,我都只会显示一个标题...
编辑 只是为了解释应该发生什么: 单击要排序的商店时,它应该只显示与该商店关联的条目。如果没有与该商店相关的水果,则标题:
本周我们对 xxxxx 的最佳商品的建议
应更改为
运气不好!看来这周我们在xxxxx商店找不到什么好水果
编辑2 尝试使用以下代码,但无论我选择哪个存储进行排序,即使我正在寻找的 div 存在,我也会收到错误消息...
$('h3.list_heading').hide();
$('h3#error').hide();
if ( $('div.availableNowListing:visible').length) {
$('h3#error').show();
} else {
$('h3.list_heading').show();
}
I'm trying to display one of two headings depending on whether some DOM elements are available / visible on the page. For some reason, it's not working... Here's the live demo so far.
I've got the following code:
$('h3.list_heading').css('display', 'none');
$('h3#error').css('display', 'none');
if ( $('div.availableNowListing').filter(':visible').length == 0) {
$('h3#error').css('display', 'block');
} else {
$('h3.list_heading').css('display', 'block');
}
At the moment, no matter what I select I only ever get one heading displayed...
EDIT
Just to explain what should happen:
When clicking on the store to sort by, it should only display entries that's associated with that store. If there's no fruit associated with that store, the heading:
Our Suggestion of the Best Available in xxxxx this Week
should change to
Bad Luck! It seems we could't find any good fruit at xxxxx store this week
EDIT 2
Tried using the following code, but nomatter which store I select to sort by, I just get the error message even if the div's I'm looking for are present...
$('h3.list_heading').hide();
$('h3#error').hide();
if ( $('div.availableNowListing:visible').length) {
$('h3#error').show();
} else {
$('h3.list_heading').show();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将
switch
中的这些行更改为此,将函数调用转移为
fadeOut()
的回调。Try changing these lines in your
switch
to this instead, shifting the function call as a callback for
fadeOut()
.不确定它是否有帮助,但尝试将代码更改为:
Not sure if it will help, but try changing the code to:
我希望这能起作用。上帝好运!
I hope this works. God luck!