How do I get the length of every image with 100px
or more of width
:
if( $('img').width( >= 100 ).length > 0 ){
[MORE CODE]
}
Use jQuery filter() like
$('img').filter(function(){
return $(this).width() >= 100;
});
You can use filter()
to achieve this:
$(window).load(function() {
var $imgs = $('img').filter(function() {
return $(this).width() >= 100;
});
// do something with $imgs...
});
Note that you should execute this under the window.load
event to ensure that the img
elements have loaded and therefore have a set width.
Try
$('img').each(function() {
if($(this).width() >= 100) {
// more code
}
});
You can do this:
$('img').each(function() {
if( $(this).width() >= 100 ){
[MORE CODE]
}
});
Use the outerWidth
to determine:
$(window).load(function() {
var $imgs = $('img').filter(function() {
return $(this).outerWidth() >= 100;
});
// do something with $imgs...
});
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.