Q:

Remove div having particular name

From the code underneath, I want to remove the previous instances of codemirror, that is both "hello" and "hii" before I can add another instance.
The jQuery is not working.
Also, if I console.log($('#source').hasClass('.CodeMirror.cm-s-default')); it always shows me false, that is it can't find the classnames.
How can I do this?
If this is my html code:
<div class = "source" id="source" name="source">
  <div class="result" id="result">
  <div class="CodeMirror cm-s-default">hello</div>
  <div class="CodeMirror cm-s-default">hii</div>
  </div>
</div>

and my javascript, jquery is:
var first = document.getElementById("source").getElementsByClassName("CodeMirror cm-s-default");
var len1 = first.length;
for(var i = 0; i < len1; i++) {
    if(first[i].className == "CodeMirror cm-s-default") {
        first[i].parentNode.removeChild(first[i]);
    }
}

A:

you can do that to remove those elements contain .CodeMirror as a class:
javascript:

document.querySelectorAll(".CodeMirror").forEach(el => el.remove());
<div class="source" id="source" name="source">
  <div class="result" id="result">
    <div class="test">Not to remove</div>
    <div class="CodeMirror cm-s-default">hello</div>
    <div class="CodeMirror cm-s-default">hii</div>
  </div>
</div>

