Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with jquery's append and prepend
    primarykey
    data
    text
    <p>I use the following code to check whether or not a certain div exists. And if it doesn't it adds it to the dom in the proper place.</p> <pre><code>if (!($("#col"+lastSlide).length)) { $('#schDisplay').prepend('&lt;div id="col' + (lastSlide) + '"&gt;&lt;/div&gt;'); } </code></pre> <p>My problem is that when this if statement checks again for a div that had already once been appended/prepended, it doesn't see the div that I added. So it will continue to add the div that was already prepended/appended.</p> <p>Is there any way this issue can be fixed?</p> <p>more code:</p> <pre><code>//fillin added column function fillElement(colnum) { var URL = 'schedule.php'; $("#col"+colnum).text("Loading...").show(); $.post(URL,{fecolnum: colnum}, function (data) { $("#col"+colnum).html(data).show(); }); } //...irrelevant code... // Create event listeners for .arrows clicks $('.arrows') .bind('click', function(){ numberOfSlides++; // Determine new position if ($(this).attr('id')=='arrow_right') { lastSlide++; currentPosition++; if (!($("#col"+lastSlide).length)) { $('#schDisplay').append('&lt;div id="col' + lastSlide + '" class="schColumn" style="float: left; width: ' +slideWidth+ 'px"&gt;&lt;/div&gt;'); fillElement(lastSlide); } } else { lastSlide--; currentPosition--; if (!($("#col"+lastSlide-2).length)) { $('#schDisplay').prepend('&lt;div id="col' + (lastSlide-2) + '" class="schColumn" style="float: left; width: ' +slideWidth+ 'px"&gt;&lt;/div&gt;'); fillElement(lastSlide-2); } } </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