Clear div element

I’m trying to clear div element of but doesnt work. any help would be appreciated. thanks
elements.movieSearched.innerHTML = ‘’;

The line you write is fine.

  • Can you console.log elements.movieSearched and paste the result in the post?

  • Are you calling a function from a onclick event or how?

Any extra detail you can add is better for you.

It comes as null when console.log(elements.movieSearched);

This is a UI function which I am calling from another class.

If it comes as null the problem is the way you’re targetting the elements. Can you include the function or any minimal example reproducing the issue?

The text that is highlighted I’m trying to clear this div.

this is the function and the div is saved as movieSearched in elements object.

export const clearSearchQuery = () => {
elements.movieSearched.innerHTML = ‘’;
}

I am calling this function here:
searchView.clearSearchQuery();

Umm It will be difficult if you don’t paste your code on codepen.io

What I can suggest is that the element is not being properly targetted, or you’re not exporting the corresponding value.


Check mozilla docs for how to export a value

elements.movieSearched is a div which has tag inside and I want to clear this element.

try pasting your js code in codepen and share the link so people here can help you better.


you can have a look at my js code