Note that there are some explanatory texts on larger screens.

plurals
  1. POOne line of table column toggling goodness. Almost
    primarykey
    data
    text
    <p>Here's my handy dandy line of code:</p> <pre><code>$('#options th.subhead').each(function(){$(this).parents('table').find('td:nth-child('+$(this).prevAll().length+')').andSelf().toggle();}); </code></pre> <p>Now... in theory, I thought that what this should do was take any th with class "subhead" in the table id'd as options and go find any td of the same column and toggle it. Oh, as well as the original th.</p> <p>Guess what. It wipes out and returns the whole contents of the table.</p> <p>I'm missing something here. Is "this" where I'm doing preVall and length no longer the this I'm thinking of?</p> <p>Update! wirey got my closer with his comment.</p> <p>I'm here now:</p> <pre><code>$('#options th.subhead').each(function(){$(this).parents('table').find('td:nth-child('+$(this).prevAll().length+')').toggle();}).toggle(); </code></pre> <p>This works great EXCEPT that it is hiding the wrong td's. It seems to be one column over on the first one, correct on the next two and one column to the left on the last one. LOL</p> <p>UPDATE 2.5 (due to bad url):</p> <p>I made a fiddle <a href="http://jsfiddle.net/MatthewDavis/8nTXB/1/" rel="nofollow">http://jsfiddle.net/MatthewDavis/8nTXB/1/</a></p> <p>UPDATE 3 Got it thanks to wirey. Here's the final fiddle! <a href="http://jsfiddle.net/MatthewDavis/8nTXB/2/" rel="nofollow">http://jsfiddle.net/MatthewDavis/8nTXB/2/</a></p> <p>And the completed line of code.</p> <pre><code>$('#options th.subhead').each(function () { $(this).parents('table').find('td:nth-child(' + ($(this).prevAll().length+1) + ')').toggle(); }).toggle(); </code></pre>
    singulars
    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