I'm trying to find (and later replace) all the divs with certain width. 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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.