Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to empty div before append
    text
    copied!<p>I'm using Freebase Search Suggest to bind a certain keyword to a getJson request. The problem is that I bind getJson functions and the corresponding .append/.prepend functions to to the input field that has the search suggest. Now if want to clear(.empty) my div that contains the result from the getJson functions i end up not being able to appennd anything.</p> <p>So every time I do a search the result div stays empty. If I not try to run the empty function and do a second search, the new information gets appended on top of the previous information. </p> <p>My site www.karsten-tietje.dk/sw</p> <pre><code>$('#myinput').suggest({key: "&lt;mykey&gt;","filter": "(all type:/music/musical_group )" }) .bind("fb-select", function(e, data) { $.getJSON("http://ws.spotify.com/search/1/track.json?q="+search_val, function(data) { items = []; $.each(data["tracks"], function(key, val) { items.push('&lt;li class="spot"&gt;&lt;span typeof="MusicRecording" property="track"&gt;&lt;p&gt;Name: &lt;strong&gt;&lt;span property="name"&gt;' + val["name"] + '&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Album &lt;strong&gt;' + val.album["name"] + '&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; Released: &lt;strong&gt;' + val.album["released"] +'&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="' + val["href"] +'"&gt;&lt;i class="icon-play-sign"&gt;&lt;/i&gt; Start Spotify&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;'); if ( key === 7 ) { return false; } }); $('#spotify-div').prepend('&lt;h3 style="border-bottom:1px solid white;"&gt;Spotify tracks&lt;/h3&gt;'); $('#spotify').html(items.join('&lt;/li&gt;')); }); }); </code></pre> <p>This is just a snippet of my some of my code. I run multiple getJson functions. </p> <p>How can I clear/empty my result div before running the other functions?</p>
 

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