# Build a wikipedia viewer - coding help

**URL:** <https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480>\
**Category:** General\
**Created:** [May 11, 2017, 5:47am UTC](https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480 "2017-05-11T05:47:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atan4583](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/atan4583/32/46070_2.png) [@atan4583](https://forum.freecodecamp.org/u/atan4583)\
**Post date:** [May 11, 2017, 5:47am UTC](https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480/1 "2017-05-11T05:47:36Z")

</div>

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

```auto
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 !

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [May 11, 2017, 6:16am UTC](https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480/2 "2017-05-11T06:16:58Z")

</div>

How about [`.empty()`](https://api.jquery.com/empty/)?

```javascript
$('#input').keyup(function(event) {
  // I'm assuming the div with this id contains the results.
  $('#display-result').empty();
  // ...
});

```

---

<div class="post-metadata">

**Author:** ![atan4583](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/atan4583/32/46070_2.png) [@atan4583](https://forum.freecodecamp.org/u/atan4583)\
**Post date:** [May 11, 2017, 6:29am UTC](https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480/3 "2017-05-11T06:29:56Z")

</div>

Thanks ! works very well. I tried .hide() on #display-result as below earlier, didn;t work. Could you explain why .empty() work ?

```auto
$('#input').keyup(function(event) {
  // I'm assuming the div with this id contains the results.
  $('#display-result').hide();
  // ...
});

```

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [May 11, 2017, 6:37am UTC](https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480/4 "2017-05-11T06:37:22Z")

</div>

[`.hide()`](https://api.jquery.com/hide/) only hides that element (as if you set its CSS to `display: none;` and you can also give it an animation duration). It’s still there in the DOM along with its children.

`.empty()` removes all of that element’s children entirely. When you used `.empty()`, all of the results from the previous search are dropped.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:56pm UTC](https://forum.freecodecamp.org/t/build-a-wikipedia-viewer-coding-help/114480/5 "2021-01-17T20:56:40Z")

</div>

Closed on January 17, 2021, 8:56pm UTC


