Counting lines, including html code after a specific line in a text using JavaScript

In this script, we first get the element containing the text using "document.getElementsByClassName()" and store it in a variable called "brl". We then split the text into an array of lines using "split("\n")" and count the number of lines using "length". We divide the result by two to determine where to insert our code.

Next, we define the code we want to inject using "var elem = "<hr>";" and replace the line of text at the specified position with the new content using "brl.innerHTML.replace()". Finally, we update the inner HTML of the element using "brl.innerHTML".

Note that you'll need to modify the JavaScript code to suit your specific needs, such as adjusting the location of the code injection or adding more complex logic.

Counting lines, including html code after a specific line in a text using JavaScript

© Manajmnt code

Share to :

Comments