How can I find the widest item (width set in css or as an attribute) on a web page using jQuery?
+4
A:
wont be fast but should do the trick
var widest = null;
$("*").each(function() {
if (widest == null)
widest = $(this);
else
if ($(this).width() > widest.width())
widest = $(this);
}
this should do the trick
I also suggest you limit the type of nodes you go through (ie. use div instead of *)
Niko
2009-08-05 13:49:20
Might want to check outerWidth() if needed.
Martin
2009-08-05 13:50:27
take care at the length of the DOM. this call can be costly.
Elzo Valugi
2009-08-05 13:55:23
Makes sense, I guess I was wishfully hoping for some kind of max function.
Jeremy
2009-08-05 13:57:00