[英]how to replace a div according to size
I'm trying to find (and later replace) all the divs with certain width. 我正在尝试查找(然后替换)具有一定宽度的所有div。 I don't have an id or a class.
我没有身份证或课程。
I tried this but it doesn't work: 我试过了,但是没有用:
$('div').filter(function(){
var width = $(this).width();
if (width > 400) {
$(this).hide();
console.log($(this));
}
});
An easier method is 一个更简单的方法是
$('div').filter(function(){ return $(this).width() > 400 });
That will select all divs that are larger than 400px
这将选择所有大于
400px
div
You can hide them using 您可以使用隐藏它们
$('div').filter(function(){ return $(this).width() > 400 }).hide();
You can do by following function 您可以通过以下功能来完成
$( "div" ).each(function() {
if($(this).width()>400)
{
$(this).hide();
}
});
It will traverse all div which has width greater than 400 and hide it. 它将遍历宽度大于400的所有div并将其隐藏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.