Child Div过滤不起作用
Filtering by Child Div not working
我试图通过查看子元素的id来过滤div元素,但我似乎无法使其正常工作,也无法找出原因。
html:
<div class="section-link" id="section-tooltip">
<div class="brand tp" style="display: none;"></div>
contents
</div>
<div class="section-link" id="section-tooltip">
<div class="brand garden" style="display: none;"></div>
contents
</div>
js:
function brand(string){
var brand = string;
$('.section-link').hide();
if ($(".section-link").children('.brand').hasClass(brand)) {
$(this).parent().show();
}
}
然后我通过chrome浏览器执行以下操作:javascript:brand("tp");
它隐藏了所有的div,但是它没有显示中带有tp元素的div
$("this")是错误的。
$(this) //this is right
编辑。另一个:它不是
.hasclass()
但是
.hasClass()
这段代码:
if ($(".section-link").children('.brand').hasClass(brand)) {
$("this").parent().show();
}
应该改为:
$(".section-link").children('.brand').each(function(){
if($(this).find(brand).length > 0){
$(this).find(brand)[0].parent().show(); //assuming onlt the first 'tp's parent needs to be shown
}
});
PS:这不需要引号
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- YouTube V3 API——按持续时间过滤相关视频信息,不;似乎不起作用
- Jquery DataTable在单个列上进行多次过滤;不起作用
- AJAX 数据过滤不起作用
- 使用 angularjs 中的特殊 $ 字符按对象过滤不起作用
- 按复选框值过滤 JavaScript 不起作用
- AngularJS复选框过滤不起作用
- 为什么不'我的过滤功能不起作用吗?(Javascript)
- 在Angularjs应用程序中,使用嵌套对象属性过滤ng repeat不起作用
- Jquery同位素过滤机制不起作用,页面只是刷新
- Child Div过滤不起作用
- 通过javascript进行的Kendo UI网格过滤不起作用
- Javascript后期过滤系统不起作用
- 当JavaScript更新一个输入值时,AngularJS的过滤不起作用
- 可过滤行在Asp.net中不起作用,但在MVC中起作用
- Jquery过滤系统多重选择不起作用