Reputation: 13555
<img class = "draggable moveable" id = "1" style="width:20px;" >...</img>
<img class = "draggable printable" id = "2" style="width:50px;" >...</img>
<img class = "draggable moveable" id = "3" style="width:10px;" >...</img>
For the case above, how to implement the jquery/css selector to get the minimum width of the same class?(which is 10px in this case)
$('.draggable').('min:width');
are there such synatx? thanks
Upvotes: 1
Views: 2267
Reputation: 144709
There is no such syntax, you can sort the element according to their width and use first
method:
$('.draggable').sort(function(a, b){
return $(a).width() > $(b).width();
}).first();
http://jsbin.com/igovaw/1/edit
Note that img
element doesn't have closing tag.
If you want to get the minimum width and not the element you can use map
method:
var w = $('.draggable').map(function(){
return $(this).width();
}).get();
var min = Math.min.apply(null, w);
Upvotes: 2
Reputation: 781804
var minwidth = undefined;
$('.draggable').each(function () {
width = parseInt($(this).css('width'));
if (minwidth === undefined || width < minwidth) {
minwidth = width;
}
});
Upvotes: 2