> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/javascript/doan-ma-javascript-de-them-ky-tu-dac-biet-vao-dau-moi-dong-trong-van-ban-nhieu-dong-ok.md).

# Đoạn mã JavaScript để thêm ký tự đặc biệt vào đầu mỗi dòng trong văn bản nhiều dòng (ok)

### Bản nâng cấp&#x20;

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .login-form {
      width: 300px;
      margin: 0 auto;
      padding: 20px;
      border: 1px solid #ccc;
      border-radius: 5px;
      background-color: #f2f2f2;
      text-align: center;
    }
    .form-group {
      margin-bottom: 15px;
    }
    .form-group textarea {
      width: 100%;
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 3px;
    }
    label {
      display: block;
      margin-bottom: 5px;
    }
    input {
      width: 100%;
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 3px;
    }
    button {
      background-color: #4CAF50;
      color: white;
      padding: 10px 20px;
      border: none;
      border-radius: 3px;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div style=" width: 800px; margin: 0 auto; ">
    <div class="form-group">
      <label for="specialChar">specialChar:</label>
      <input type="text" id="specialChar" name="specialChar">
    </div>
    <div class="form-group">
      <label for="originalText">originalText:</label>
      <textarea id="originalText" name="note" rows="10"></textarea>
    </div>
    <pre id="result"></pre>
    <button id="getmodifiedText" type="submit" style=" user-select: none; ">Submit</button>
  </div>
  <script>
    function addSpecialCharToLines(text, specialChar) {
      // Split the text into an array of lines
      const lines = text.split('\n');
      // Add the special character to the beginning of each line
      var modifiedLines = lines.map(line => specialChar + " " + line.trim());
      modifiedLines = modifiedLines.filter(function (el) {
        return el != specialChar + " ";
      });
      console.log(modifiedLines);
      // Join the modified lines back into a single string
      var modifiedText = modifiedLines.join('\n');
      console.log(modifiedText);
      return modifiedText;
    }
    document.getElementById("originalText").addEventListener("input", function () {
      var originalText = document.getElementById("originalText").value;
      var result = document.getElementById("result");
      var specialChar = document.getElementById("specialChar").value;
      if (specialChar == "") {
        specialChar = "▪️";
      }
      const modifiedText = addSpecialCharToLines(originalText, specialChar);
      result.innerText =  modifiedText;
    });
  </script>
</body>
</html>
```

<figure><img src="/files/Z5DOTYN0noiZAqboh6Ea" alt=""><figcaption></figcaption></figure>

Bản gốc

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function addSpecialCharToLines(text, specialChar) {
      // Split the text into an array of lines
      const lines = text.split('\n');
      // Add the special character to the beginning of each line
      const modifiedLines = lines.map(line => specialChar + " " + line.trim());
      modifiedLines.shift();
      modifiedLines.pop();
      // Join the modified lines back into a single string
      const modifiedText = modifiedLines.join('\n');
      return modifiedText;
    }
    // Example usage:
    const originalText = `
    This is the first line.
    This is the second line.
    This is the third line.
    `;
    const specialChar = '▪️';
    const modifiedText = addSpecialCharToLines(originalText, specialChar);
    console.log(modifiedText);
  </script>
</body>
</html>
```

<figure><img src="/files/zqc7Vxafx3uaA5FYnHaa" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://javascriptuse.gitbook.io/javascript/doan-ma-javascript-de-them-ky-tu-dac-biet-vao-dau-moi-dong-trong-van-ban-nhieu-dong-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
