简体   繁体   中英

$('.small').css('width',$(this).siblings('.large').css('width'));

I have two type of different div : some are small and some are large.

I would like the small ones to have the same width than the large ones.

It seems I can't use $(this) inside a .css attribute.

http://jsfiddle.net/Gs2kD/12/

You need to include jQuery instead of mootools.

And you need to define a callback function along with css()

This will probably look like this:

$('.small').css('width',function(){ 
    return $(this).siblings('.large').css('width'); 
});

Demo

http://jsfiddle.net/Gs2kD/15/

$('.small').each(function(){
   $(this).css('width', $(this).siblings('.large').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