Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery remove and add a div back when the text in a div has changed
    primarykey
    data
    text
    <p>I have a div slideshow. I have several divs with a class named rotate in each one of them and there are more divs within that div. My task is to check if one of the divs which have a postfix as _note3 contain a 0 to exclude that slide from the slideshow. The zero would be coming from a SQL server. I am able to exclude it from the slideshow but I have been unable to put it back in when the zero is removed. I am wondering if someone has any idea what I am doing wrong and help me find a solution.</p> <p>My code looks like this:</p> <pre><code> $(document).ready(function() { var note3 = []; var divsCount = 0; var ids = []; var count = 0; var divs = []; var removed = []; for(var x = 0; x &lt; $(".rotate").length; x++) { notes3(divsCount); getRotate(divsCount); divsCount++; } // I find all the _note3 divs function notes3(index) { note3.push($('div[id*="_note3"]:eq(' + index + ')').attr("id")); } for (var t = 0; t &lt; $(".rotate").length; t++) { $(".rotate").eq(t).hide(); } // I find put all the rotate divs in an array function getRotate(index) { divs.push($('div[class*="rotate"]:eq(' + index + ')').attr("class")); } // This is where my rotation happens function setsRotation() { $(".rotate").eq(count).hide(); if (count &lt; $(".rotate").length - 1) { count++; } else { count = 0; } // If it contains a zero I remove it if($("#" + note3[count] + "").text() === $.trim("0")) { // I put the div index in an array removed.push(count); $('div[class*="rotate"]:eq(' + count + ')').remove(); // If it does not contain a zero } else { // If the index is in the removed array I take it out and append the div if($.inArray(count, removed) &gt; - 1) { removed.splice($.inArray(count, removed), 1); $("#slideshow").append(divs[count]); } $('div[class*="rotate"]:eq(' + count + ')').show(); } } setInterval(setsRotation, 1000); }); </code></pre> <p>Thanks in advanced!</p> <p>HTML:</p> <pre><code>&lt;div id="slideshow"&gt; &lt;div class="rotate" id="jrkC"&gt; &lt;div&gt; &lt;div id="JerkChknLg_desc" class="descript"&gt;&lt;/div&gt;&lt;div id="JerChknLg_note3"&gt;&lt;/div&gt; &lt;table class="pepper"&gt; &lt;tr&gt; &lt;td class="size"&gt;Regular ds&lt;/td&gt; &lt;td class="size"&gt;Large&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="value"&gt;&lt;div id="JerkChknSm_price"&gt;&lt;/div&gt;&lt;/td&gt; &lt;td class="value"&gt;&lt;div id="JerkChknLg_price"&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div class="frontPic"&gt;&lt;img src="media/img/JerkChkn.jpg"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="rotate" id="soups" &gt; &lt;div id=""&gt; &lt;div id="SoupLrg_desc" class="descript"&gt;&lt;/div&gt;&lt;div id="SoupLrg_note3"&gt;&lt;/div&gt; &lt;table class="pepper"&gt; &lt;tr&gt; &lt;td class="size"&gt;Regular&lt;/td&gt; &lt;td class="size"&gt;Large&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="value"&gt;&lt;div id="SoupSm_price"&gt;&lt;/div&gt;&lt;/td&gt; &lt;td class="value"&gt;&lt;div id="SoupLrg_price"&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div class="frontPic"&gt;&lt;img src="media/img/Soup.jpg"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </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.
    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