javascript - Get widest element in a jQuery set -
let's have bunch of <span>
elements different text content.
how can widest <span>
?
jquery fine. care identifying span, not value of width itself.
a similar question here. value of width.
here's how i'd start:
$('span').each(function(id, value){ if ($(this).width() > w) { largestspan = id; } });
var maxwidth = 0; var widestspan = null; var $element; $("span").each(function(){ $element = $(this); if($element.width() > maxwidth){ maxwidth = $element.width(); widestspan = $element; } });
Comments
Post a Comment