-3

I'm currently using jQuery to remove a div, but I'd like my project to not have to rely on a third party library for it to work. Say my div had the class .main, if I was using jQuery I'd write:

$("div.main").remove()

How would I do this with JS only?

Verpz
  • 131
  • 3
  • 13
  • 3
    Come on, use the search. Is it so hard? – Tomalak Feb 27 '16 at 11:05
  • I did use the search – Verpz Feb 27 '16 at 11:07
  • 2
    No, you didn't. There are hundreds of questions with this topic on Stackoverflow and thousands of tutorials, blog posts, documentation pages and whatnot on the wider Internet. They would have been impossible to miss, if you only had tried half as long as it took you to write down this question. – Tomalak Feb 27 '16 at 11:14

2 Answers2

5

Duplicate question but try this: (Set an id for it)

var elem = document.getElementById("myDiv");
elem.parentNode.removeChild(elem);

or take a look at this topic:

Remove all elements of a certain class with JavaScript

Community
  • 1
  • 1
Pedram
  • 15,766
  • 10
  • 44
  • 73
0

Something like this :

el.parentNode.removeChild(el);

IE8+

oiledCode
  • 8,589
  • 6
  • 43
  • 59