简体   繁体   中英

Jquery or Javascript: How to find all html elements which has image more than 500px and less than 2000px?

I want to find all html elements with jquery or javascript which has image more than 500px and less than 2000px. Here is my code.

$("*").each(function() {
        var image = jQuery(this);
        if ((image.attr("width") >= 512) && (image.attr("width") <= 2048)){
            //do something
        }
    }

But with this code I can only find img tag and also which we give width static. Ex: working not working And also I can't find div elements or something. I want to find all html elements which has image where we see width is more than 500px and 2000px. For example: <div class="back_img"></div> css: .back_img{background-image:url("img/img.png")} I want to find this also. Is there anybody who knows solution?

Try:

$("*").each(function() {
        var image = jQuery(this);
        if ((image.width() >= 512) && (image.width() <= 2048)){
            //do something
        }
    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM