Radu033 Radu033 - 21 days ago 6
CSS Question

How do I affect only some items in my array Jquery

My Wordpress posts shows images, all images have the .aligncenter class.
I would like the images which are less than 400px to have the

display:inline-block;
style and to reduce their size to 40%.

I tried it this way:

var size = jQuery(".aligncenter").width();
if(jQuery( size < 400)) {
jQuery(".aligncenter").css({
'display' : 'inline-block',
'width' : '40%'
});
}


This script affects all images in the post, not only the ones that are less than 400px. How can I affect only images that are less than 400px?

Answer
$(".algincenter").each(function(){ if($(this).width()<400){$(this).css(...) } })