Petar Mijović Petar Mijović - 1 month ago 7
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" >

</div>


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

$("#forDelete").Remove();


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

Answer

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

$(".forDelete").remove();

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

$("#world-map").remove();

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