Note that there are some explanatory texts on larger screens.

plurals
  1. POGet ID of Previous Table in the DOM issue
    primarykey
    data
    text
    <p>When i use the fn below it returns the current table as previous..</p> <p>I "tweaked" the index in the slice to get the results I was looking for. This is a hack and I am looking for explanation/answer if there is something I am missing. </p> <p>Each tables is nested in a div or 2. But using the selector I would assume the previous would be the previous of the selector specified. </p> <p>hack: ? $all.slice(0, $all.index(this)<strong>-10</strong>).reverse() : $all.slice($all.index(this) <strong>+ 2</strong>)</p> <p>original func:</p> <pre><code>$.fn.reverse = function () { return this.pushStack(this.get().reverse(), arguments); }; // create two new functions: prevALL and nextALL. $.each(['prev', 'next'], function (unusedIndex, name) { $.fn[name + 'ALL'] = function (matchExpr) { // get all the elements in the body, including the body. var $all = $('body').find('*').andSelf(); // slice the $all object according to which way we're looking $all = (name == 'prev') ? $all.slice(0, $all.index(this)).reverse() : $all.slice($all.index(this) + 1) ; // filter the matches if specified if (matchExpr) $all = $all.filter(matchExpr); return $all; }; }); </code></pre> <p>elements: these are looped, <strong>I am trying to navigate from one table to the next using up, down, left right arrow keys.. and need to be able to get the ID of the previous &amp; next table</strong></p> <pre><code> "&lt;div id='divOuter" + div.divCode + "' class='BoxOuterDiv' &gt;" + " &lt;div id='div" + div.divCode + "' class='BoxDiv' &gt;" + " &lt;table class='grid' id='" + div.divCode + "' width='100%'&gt;" + " &lt;tr&gt;" + " &lt;td class='col0' width='125px' nowrap='nowrap'&gt;" + " &lt;span id='spn0" + div.divCode + "' class='rgCollapse' onclick='Collapse(this)'&gt;&amp;nbsp&amp;nbsp&lt;/span&gt;" + " Division: " + div.divCode + " &lt;/td&gt;" + " &lt;td class='col1' width='5%' style='padding-left:15px' nowrap='nowrap'&gt;" + " Description: " + " &lt;/td&gt;" + " &lt;td class='col2' width='40%' nowrap='nowrap'&gt;" + " &lt;input class='grid' type='text' id='dvDesc" + div.divCode + "' value='" + div.divDesc + "' style='width: 400px' maxlength='60' /&gt;" + " &lt;/td&gt;" + " &lt;td class='col3' width='50%' align='right' nowrap='nowrap'&gt;" + " &lt;input type='button' id='btnDv" + div.divCode + "' value='Add Business Unit' style='align:right' onclick='AddMfRow(this);' /&gt;" + " &lt;/td&gt;" + " &lt;/tr&gt;" + " &lt;/table&gt;" + " &lt;/div&gt;" + "&lt;div id='divWrapper" + div.divCode + "'&gt;" </code></pre> <p>Credit to Author: <a href="https://stackoverflow.com/questions/322912/jquery-to-find-all-previous-elements-that-match-an-expression">jQuery to find all previous elements that match an expression</a></p> <p>Another question.. This blows up in IE! any idea why??</p> <pre><code>$.fn.reverse = function () { return this.pushStack(this.get().reverse(), arguments); </code></pre> <p>};</p> <p>// create two new functions: prevALL and nextALL. $.each(['prev', 'next'], function (unusedIndex, name) { $.fn[name + 'ALL'] = function (matchExpr) { // get all the elements in the body, including the body. var $all = $('body').find('*').andSelf();</p> <pre><code> // slice the $all object according to which way we're looking $all = (name == 'prev') ? $all.slice(0, $all.index(this)-10).reverse() : $all.slice($all.index(this) + 2) ; // filter the matches if specified if (matchExpr) $all = $all.filter(matchExpr); return $all; }; </code></pre> <p>});</p>
    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.
    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