JavaScript 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]);
    }
}
Answer:1

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>
Answer:2

Maybe simply like this?

$(function() {
  $(".CodeMirror").remove();
});
Answer:3

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" ...

  1. embed google drive video
  2. embed google drive folder
  3. embed google drive pdf
  4. embed google drive image
  5. embed google drive video squarespace
  6. embed google drive video in powerpoint
  7. embed google drive file
  8. embed google drive audio
  9. embed google drive link
  10. embed google drive folder wordpress
  11. embed google drive video in gmail
  12. embed google drive wordpress
  13. embed google drive folder iframe
  14. embed google drive video in email
  15. embed google drive document
  16. embed google drive video in slides
  17. embed google drive document in website
  18. embed google drive video in canvas
  19. embed google drive search
  20. embed google drive video in wordpress

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} ...

  1. javascript convert array to string
  2. javascript convert array to object
  3. javascript convert array to json
  4. javascript convert array to map
  5. javascript convert array to set
  6. javascript convert array of strings to numbers
  7. javascript convert array to csv
  8. javascript convert array to comma separated string
  9. javascript convert array to list
  10. javascript convert array of objects to array of strings
  11. javascript convert array to object keys
  12. javascript convert array to string with spaces
  13. javascript convert array into object
  14. javascript convert array to number
  15. javascript convert array to string without commas
  16. javascript convert array to arguments
  17. javascript convert array to nested object
  18. javascript convert array of objects to csv
  19. javascript convert array to query string
  20. javascript convert array buffer to string

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 ...

  1. using mind map to write a book

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 ...