Namlind
Namlind

Reputation: 47

How to select all text inside Contenteditibale div?

I'm trying to create multiple Contenteditibale div with text inside , so when i want to select the whole text (in all the div's) using either the mouse or ctrl + a , using only vanilla js .

body {
 font-size:16px;
 }
 .wrapper {
  display: flex;
    justify-content: center;
    align-items: center;
    flex-direction:column;
    width: 100vw;
    height :100%
    }
    
 .contenteditable {
  width:400px;
  height:200px;
  border:4px dashed red;
  
  }
  .contenteditable:focus {
  outline : red 2px solid ;
  }
<div class=wrapper>
<div class="contenteditable" contenteditable="true"></div>
<div class="contenteditable" contenteditable="true"></div>
<div class="contenteditable" contenteditable="true"></div>
<div class="contenteditable" contenteditable="true"></div>
<div class="contenteditable" contenteditable="true"></div>
</div>

Upvotes: 0

Views: 37

Answers (1)

Ran Turner
Ran Turner

Reputation: 18116

You can use textContent;

var node = document.getElementsByClassName('wrapper')[0];
var text = node.textContent;// get's all the text inside the wrapper element

Upvotes: 1

Related Questions