skip to Main Content
function callBack(data1, predicted_label){
    const resultParagraph = document.getElementById("resultParagraph"); 
    resultParagraph.textContent = `Sentiment: ${predicted_label}`;
    const historyList = document.getElementById("historyList");
    const listItem = document.createElement('li');
    listItem.textContent = `Text: ${data1} Sentiment: ${predicted_label}`;
    historyList.prepend(listItem);  }

In this code i want to add a new line between Text: ${data1} Sentiment: ${predicted_label}.

I’ve tried adding n, tried adding a <br> tag but nothing seems to work

2

Answers


  1. HTML rendering doesn’t respect newlines – you’ll need to use innerHTML instead of textContent and add a <br> tag where you want the line break

    Login or Signup to reply.
  2. You can use CSS to style the list item to display "Text" and "Sentiment" on separate lines.

    function callBack(data1, predicted_label) {
        const resultParagraph = document.getElementById("resultParagraph");
        resultParagraph.textContent = `Sentiment: ${predicted_label}`;
        const historyList = document.getElementById("historyList");
        const listItem = document.createElement('li');
        listItem.textContent = `Text: ${data1}nSentiment: ${predicted_label}`;
        listItem.style.whiteSpace = "pre-line"; // style for line breaks
        historyList.prepend(listItem);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search