简体   繁体   中英

target images inside a div by it's name

I'm trying to create a button that resizes down images inside it's div,

function aumenta(){
    var mydiv = $('div[name|="visualizacoes"]');
    var curr_width = parseInt(mydiv.style.width);
    var curr_height = parseInt(mydiv.style.height);

    if (curr_width < 4123) {            
        mydiv.style.width = (curr_width + 412) +"px";
        mydiv.style.height = (curr_height + 466) +"px";
    }
    }

it's not working, maybe this is not the way to get the element's name? My problem is that i have several div's hidden that show up on menu click, I'm trying to get all of them to resize even if they're hidden, that's why im targeting it's name, could be the class as well!! Please help! Thanks

Create a class, then make all the images a member of that class.

If you do this, you can then use the jQuery "each()" method to iterate through each element, and manipulate them in a loop...

$('.<classname>').each(function(e){
    var element = $(this);
    var currWidth = element.width();
    var currHeight = element.height();

    if( currWidth < 4123 ){
        element.width( currWidth + 412 );
        element.height( currHeight + 412 );
    }
});

In the above I've also used the jQuery width() and height() methods to get and set the elements height and width.

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