Hello, need some guidance on JQuery code in my Wikipedia Viewer :
After dynamically building the html page to display the search result sets (returned from the API call), I want to dismiss all the result sets when I re-enter the search box to start a new search. So far, I can only dismiss the first result set. Can the JQuery experts on here please help me ? Below is my code snippets
html
<div class="row form-group">
<div class="col-md-8 col-md-offset-2 text-center">
<input type="text" class="search_box" id="input" placeholder="Search Wikipedia">
<button type="submit" class="btn btn-grn searchSubmit" id="searchSubmit">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
<button type="submit" class="btn btn-grn" id="randomPage"><a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">
Feelin' Lucky?</a>
</button>
</div>
</div>
<div id="display-result" class="col-md-6 col-md-offset-3 ">
</div>
JS
.success(function(response) {
var dat = JSON.stringify(response);
console.log(dat);
console.log(response);
response.query.pages.forEach(function(resp) {
$('#display-result').append(
"<a href='" + resp.fullurl + "' target= '_blank'><div id='result' class='results'><h3>" + resp.title + "</h3><p = class='extract'>" + resp.extract + "</p></div>");
})
});
$("#input").keyup(function(event) {
$("#result").hide(); //this only hides the first result set, even if placed in a for-loop
if (event.keyCode == 13) {
$("#searchSubmit").click();
}
});
Thanks !