vegas
vegas

Reputation: 111

why there is no line ends in console logging a html

pls write this in #cedit

lorem
ipsum
dolor

console will be:

lorem<div>ipsum</div><div>dolor</div> 

how to get line ends in console like this:

lorem
<div>ipsum</div>
<div>dolor</div> 

so I have one single object - html and not multiple objects to insert a '\n' between them

$('#cedit').on('input', function(){
let a = $(this).html();
console.log(a);
});
#cedit{
background:gold;
min-height:99px;
padding:9px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='cedit' contenteditable></div>

Upvotes: 0

Views: 46

Answers (1)

Carsten Massmann
Carsten Massmann

Reputation: 28196

This would do it:

$('#cedit').on('input', function(){
let a = $(this).html();
console.log(a.replaceAll("<div","\n<div"));
});
#cedit{
background:gold;
min-height:99px;
padding:9px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='cedit' contenteditable></div>

Upvotes: 1

Related Questions