Petar Mijović Petar Mijović - 1 year ago 105
Javascript Question

programmatically removing html element

I have a situation with my web api web application. When started the application shows empty map, when I press search another map appears. My question is how to programmatically remove first map. These are the pictures that explain the situation(on start):

enter image description here

When search is clicked:
enter image description here

This is my html code for map:

<div id="world-map" class="forDelete" style="width: 600px; height: 400px" >


An this is what i tried. I added next line of code to the function that draws map when search is clicked.


Any suggestions why this doesn't work? Or possible solution?
p.s. I code in html and java script for the first time.

Answer Source

It's a class so it's not with a hash. It should be then like this:


Otherwise if you want to use the idi of your element:


Also remember JS is caps sensitive so it is not .Remove but .remove()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download