tags:

views:

115

answers:

1

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
Might want to check outerWidth() if needed.
Martin
take care at the length of the DOM. this call can be costly.
Elzo Valugi
Makes sense, I guess I was wishfully hoping for some kind of max function.
Jeremy