79670513

Date: 2025-06-18 11:14:30
Score: 1.5
Natty:
Report link

var startStatus = "less";

function toggleText() {
  var text = "Here is the text that I want to play around with";

  if (text.length > 12) {
    if (startStatus == "less") {
      document.getElementById("textArea").innerHTML = `${text.substring(0, 12)}...`;
      document.getElementById("more|less").innerText = "More";
      startStatus = "more";
    } else if (startStatus == "more") {
      document.getElementById("textArea").innerHTML = text;
      document.getElementById("more|less").innerText = "Less";
      startStatus = "less";
    }
  } else {
    document.getElementById("textArea").innerHTML = text;
  }
}

toggleText();
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div>
    <p id="textArea">
      <!-- This is where i want text displayed-->
    </p>
    <span><a
          id="more|less"
          onclick="toggleText();"
          href="javascript:void(0);"
        ></a
      ></span>
  </div>
</body>

</html>

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • RegEx Blacklisted phrase (1): i want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: YOGALAKSHMI S