Clearing previous results in Wikipedia Viewer

Clearing previous results in Wikipedia Viewer
0

#1

I’ve mostly completed the Wikipedia Viewer project but have not figured out how to clear all previous search results after I search for a new word. I know that I have to use the .empty() command, but I can’t figure out where to place it. I would appreciate it if someone could take a look at my code and tell me how to fix this issue: https://codepen.io/Crimson_Macaw/pen/weNWEa


#2

In your case, right above the loop:

$("#searchList").empty();
for (var i = 0; i < link.length; i++){
// your other code
}

#3

Thanks Dave, I thought I had tried placing the .empty() command almost everywhere, but obviously did not try placing it above the loop.


#4

My loop created a big string of HTML, I only needed to overwrite the HTML of a DIV each time, no empty process needed.