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]);
}
}
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>
Maybe simply like this?
$(function() {
$(".CodeMirror").remove();
});
I have a folder in Google Drive and I need to embed it on my website. I used this code: <iframe src="https://drive.google.com/embeddedfolderview?id=0B-cjMH6T4IV5bzlkUmpTWkhQOTg#grid" width="700" ...
I have a folder in Google Drive and I need to embed it on my website. I used this code: <iframe src="https://drive.google.com/embeddedfolderview?id=0B-cjMH6T4IV5bzlkUmpTWkhQOTg#grid" width="700" ...
I have a set of values in an array where each value has an ID and LABEL. Once I have the value array and type console value[0] and value[1], the output is: value[0] Object {ID: 0, LABEL: turbo} ...
I have a set of values in an array where each value has an ID and LABEL. Once I have the value array and type console value[0] and value[1], the output is: value[0] Object {ID: 0, LABEL: turbo} ...
I'm am very new to programming and I am trying to solve a problem where I have to convert an array of Fahrenheit values, to Celsius. Though I am not too sure where to start with .map and I would ...
I'm am very new to programming and I am trying to solve a problem where I have to convert an array of Fahrenheit values, to Celsius. Though I am not too sure where to start with .map and I would ...
I am trying to set up the following architecture: a core React application that gets built with some basic functionality, and the ability to load additional React components at runtime. These ...
I am trying to set up the following architecture: a core React application that gets built with some basic functionality, and the ability to load additional React components at runtime. These ...