Note that there are some explanatory texts on larger screens.

plurals
  1. POfunction to handle non-uniform jquery list
    primarykey
    data
    text
    <p>I'm building a function that, for each item with a given class, loops through each of them, looking for the tallest one, then sets the rest to that same height. </p> <p>The problem is that I'm only using a single class name and I am catching different elements types that should each be handled uniquely according to their element type (i.e. LIs vs DIVs)</p> <pre><code>var makeModulesSameHeight = function() { var maxHeight, $arrAllTargets = $(".makeEqualHeight"); maxHeight = getMaxHeight($arrAllTargets); $arrAllTargets.css("height",maxHeight); console.log("max height for every friggin' thing is " + maxHeight); }; var getMaxHeight = function($arrModules){ var myHeight,maxHeight = 0; $arrModules.each(function(){ myHeight = $(this).outerHeight(); maxHeight = (myHeight &gt; maxHeight) ? myHeight : maxHeight; }); return maxHeight; }; makeModulesSameHeight(); </code></pre> <p>Fiddle--> <a href="http://jsfiddle.net/scott_in_ct/bpKxQ/" rel="nofollow">http://jsfiddle.net/scott_in_ct/bpKxQ/</a></p> <p>Does anyone have a good way to make this work according to element type? </p> <p>I was thinking of something along the lines of:</p> <pre><code>// initialize empty list to contain unique tag names // select jquery master list of all items with same class // for each item in jquery master list // - if this tagName is not in list above, add it // then // for each item in tagName list // - create new array specific to that tagName (not sure how to do this, actually. I think I'm getting confused with PHP's associative array.) I guess I can always just remember what ordinal number goes with which item. // for each item in jquery master list // - move this item into its appropriate tag array // for each tag array // - set each item in array to max height using previous implementation </code></pre> <p>This seems like a kludgy way to do this with multiple loops and such. I'm looking to see if anyone has a more efficient approach, perhaps using memoization or something cool. :^)</p> <p>OR</p> <pre><code>// for each item in master array // -- look to a common parent and set height according to its descendents // (somehow) // profit! </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload