Here is a text, and when we add content through the textbox, then every new line adds into a new div class with quiz in inner div.
Just Like This:
<div id="inner">
<div class="quiz">this is line one</div>
<div class="quiz">this is second line</div>
<div class="quiz">this is third line</div>
<div class="quiz">and so on...</div>
</div>
But I want to add a unique id in the "n" Number series from "1" on every quiz class Just Like this output I want when we add content through this textbox. Like That:
<div id="inner">
<div id="1" class="quiz">this is line one</div>
<div id="2" class="quiz">this is second line</div>
<div id="3" class="quiz">this is third line</div>
<div id="4" class="quiz">and so on...</div>
</div>
My Whole Code is:
const sendButton = document.getElementById('send-btn');
const textArea = document.getElementById('input');
const innerDiv = document.getElementById('inner');
var message = textArea.value;
sendButton.addEventListener('click', function() {
// split the textarea entries into an array
let lines = (textArea.value).split("\n");
// iterate over each line, creating a div/span and inserting into the DOM
lines.forEach( (line) => {
let encodedLine = encodeHtmlEntity(line);
let newElement = `<div class="quiz">${encodedLine}</div>`;
innerDiv.innerHTML += newElement;
});
// reset the textarea
textArea.value = '';
});
function encodeHtmlEntity(input) {
var output = input.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
return '&#' + i.charCodeAt(0) + ';';
});
return output;
}
<div id="inner"> </div>
<br>
<textarea class="input" id="input" placeholder="Message..."></textarea><br>
<button class="waves-effect waves-light" id="send-btn">Add Content</button>
What some new lines of code I need to write, anyone can help me.