2
Good morning, recently I was writing this code and had some problems, I would like to get the number of lines of content from a div "contenteditable" and take these values (numbers) to another div.
Follow my simplified code:
$(document).one('paste',function(e) {
setTimeout(function() {
var x = $('#input').contents().length;
$("#line").append ('<div>'+x);
},100);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<div contenteditable="true" id="input" spellcheck="false"></div>
<div id="line"><div>0</div></div>
The results I’m getting when the number of lines in #input is 4:
<div id="line">
<div>0</div>
<div>4</div>
</div>
Simulation of the results I’d like to get when the number of lines in #input is 4:
<div id="line">
<div>0</div>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
Just remembering that in <div id="line"><div>0</div></div>
we already have a zero initially.
Briefly the problem is that I am getting only one div with the value of all lines, I would like to have one div for each line.
Hoping for some help, thank you.
I didn’t quite understand ... is it something like this? https://jsbin.com/pisozen/2/edit?html,css,js,output
– balexandre
@balexandre Yes, your example is basically what I want, please post it as an answer, later I will see the next ones and I will evaluate the best. Thank you!
– Lima