Why doesn’t $(".elm").width() return the width of all elements combined? Is this by design, or some sort of bug?
Or is there some other way to get the width of all elements combined other than this:
var width = 0;
$(".elm").each(function() {
width += $(this).width();
});
Width doesn’t return the combined width by design, because this may not be the expected value you’re looking for.
There is no easy way of telling if the elements are positioned horizontally one after each other. They can be anywhere on the page or even within each other, because a jQuery object may be a combined or edited list of elements.
What does a combined width of elements mean that are cluttered all over your page?
You already found the easiest way of getting the combined width 🙂