# Need help with clearing the images after a new search request

**URL:** <https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 4, 2021, 2:21pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312 "2021-08-04T14:21:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohersi1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ohersi1/32/134048_2.png) [@ohersi1](https://forum.freecodecamp.org/u/ohersi1)\
**Post date:** [August 4, 2021, 2:21pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/1 "2021-08-04T14:21:35Z")

</div>

I can’t figure out how the clear the posters after a new search request I tried my best on my own but help would be appreciated. I’ve attached screenshots it’s a tv show search and it gets posters from an API for posters matching the query

 ![no 2](https://global.discourse-cdn.com/freecodecamp/original/3X/5/a/5a72335cd8ecc858e90a0b506758a2e8ae3b871b.png)

---

<div class="post-metadata">

**Author:** ![ohersi1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ohersi1/32/134048_2.png) [@ohersi1](https://forum.freecodecamp.org/u/ohersi1)\
**Post date:** [August 4, 2021, 2:22pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/2 "2021-08-04T14:22:14Z")

</div>

Forgot to attach this thank you in advance for your help

 ![Screenshot 2021-08-04 at 14.46.51](https://global.discourse-cdn.com/freecodecamp/original/3X/0/f/0f446ef6d6273fceb2ccaadca30268aeb8622412.jpeg)

---

<div class="post-metadata">

**Author:** ![snowmonkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snowmonkey/32/241579_2.png) [@snowmonkey](https://forum.freecodecamp.org/u/snowmonkey)\
**Post date:** [August 4, 2021, 2:53pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/3 "2021-08-04T14:53:18Z")

</div>

Couple things. First, querySelectorAll doesn’t return an HTML element, it returns an array (a NodeList, but works as an array) - and an array doesn’t have a removedAttribute.

Second, getting rid of an image’s src doesn’t removes the image. Consider a looping mechanism of your choice over all the images and, for each image, use [DevDocs](https://devdocs.io/dom/childnode/remove)

---

<div class="post-metadata">

**Author:** ![ohersi1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ohersi1/32/134048_2.png) [@ohersi1](https://forum.freecodecamp.org/u/ohersi1)\
**Post date:** [August 4, 2021, 3:46pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/4 "2021-08-04T15:46:57Z")

</div>

tried to implement what you said but it didn’t work am I close? any further help please?

 ![no 3](https://global.discourse-cdn.com/freecodecamp/original/3X/7/3/736366dde91f290c128b27aa373b8c353a5b14dc.png)

---

<div class="post-metadata">

**Author:** ![snowmonkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snowmonkey/32/241579_2.png) [@snowmonkey](https://forum.freecodecamp.org/u/snowmonkey)\
**Post date:** [August 4, 2021, 4:17pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/5 "2021-08-04T16:17:11Z")

</div>

What do you get if you console.log `allImg`? I’m wondering if we ever reach that line…

---

<div class="post-metadata">

**Author:** ![ohersi1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ohersi1/32/134048_2.png) [@ohersi1](https://forum.freecodecamp.org/u/ohersi1)\
**Post date:** [August 4, 2021, 4:50pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/6 "2021-08-04T16:50:54Z")

</div>

The console.log doesn’t run so i think you are right.

---

<div class="post-metadata">

**Author:** ![snowmonkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snowmonkey/32/241579_2.png) [@snowmonkey](https://forum.freecodecamp.org/u/snowmonkey)\
**Post date:** [August 4, 2021, 5:24pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/7 "2021-08-04T17:24:55Z")

</div>

Try defining `allImg` before the if statement, creating the array, and then check `if( allImg.length > 0){ ... }`

---

<div class="post-metadata">

**Author:** ![ohersi1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ohersi1/32/134048_2.png) [@ohersi1](https://forum.freecodecamp.org/u/ohersi1)\
**Post date:** [August 4, 2021, 6:45pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/8 "2021-08-04T18:45:26Z")

</div>

Thank you so much snowmonkey that actually worked god bless you, this problem was eating away at me for 3 days

---

<div class="post-metadata">

**Author:** ![snowmonkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snowmonkey/32/241579_2.png) [@snowmonkey](https://forum.freecodecamp.org/u/snowmonkey)\
**Post date:** [August 4, 2021, 7:07pm UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/9 "2021-08-04T19:07:40Z")

</div>

Glad we figured it out, might be worth working into the curriculum somewhere…

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [February 3, 2022, 7:07am UTC](https://forum.freecodecamp.org/t/need-help-with-clearing-the-images-after-a-new-search-request/472312/10 "2022-02-03T07:07:54Z")

</div>

Closed on February 3, 2022, 7:07am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
