Javascript For-loop

Hi Techiee,

I have 100 number of paragraph binding from database to Html code using List in mvc.But Inside each Paragraph i need to give one Br tag.Where the one sentence finished.

Here i attached my code and javascript.

But My code will give the Br tag for First paragraph.Rest of 99 paragraph Br tag is not taking it, Any Solution for it.

Ex:(Paragraph)

What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard. Dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book it

 <html>

<head>

</head>

<body onload="myFunction()"> 

 @foreach (ImgViewModel ourteamdesc in Model.OurTeamDesc)

{

<div id="demo" >

<p>@tbl.Designation</p>

</div>

}

 

<script>

function myFunction() {

var str = document.getElementById("demo").innerHTML;

var res = str.split(".").join("<br />");

document.getElementById("demo").innerHTML = res;

}

</script>

 </body>

</html>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

Hello,
there is no need to create new javascript function to manipuate the DOM, since you are using an MVC framework, look at the prebuild features of the framework.
In the foreach block you are looping throw a list , but you are not using there elements in the core of your code.
Best regards