Line Break in all div's html with JavaScript

Hi E's,
I try to get a solution for make like a simple custom beautify html.
In practice, every time the script found a div close (</div>), create a line break, like this:
var code_html = '<div id="all"><div class="one">hello, this is a test</div><div class="two">hello, test again</div><div class="one">hello, this is great</div></div>';

Open in new window

The objective is transform the variable code_html in this (create a line break for each </div>):
var code_html = '<div id="all"><div class="one">hello, this is a test</div>
<div class="two">hello, test again</div>
<div class="one">hello, this is great</div>

Open in new window

How I can do that transformation i JavaScript, or in jQuery?

The best regards,
Pedro ChagasWebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you want to create this in your code itself ?
Pedro ChagasWebmasterAuthor Commented:
Hi @Leakim,
I create my own code editor for compose some articles in html, but every time I save the code comes like this:
<div id="David_Bowie_Psaablo_Picasso"><div class="row"><div class="col s1 m3 l3 xl3"></div><div class="col s10 m6 l6 xl6"><div class="video-container"><iframe width="853" height="480" title="David Bowie - Psaablo Picasso" src="" scrolling="no" allowfullscreen="allowfullscreen"></iframe></div></div><div class="col s1 m3 l3 xl3"></div></div></div>
I have above code inside a javascript variable, and I want organize/beautify my code.

Regards, JC
OK, so we just need to add a \n after each </div>, check here and confirm please :



// checking :

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Pedro ChagasWebmasterAuthor Commented:
Hello again,
I don't understand your solution.
First, I generate dynamic code, because that I don't known where I have to make the line break, so the script have to detect "</div>", and do automatically the line break in every </div>.
Did I express myself wrong?

Try this :

codeToBeautify = codeToBeautify.split("</div>").join("</div>\n");

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pedro ChagasWebmasterAuthor Commented:
Good morning.
I will try your solution this night.
Please wait.

~ JC
Pedro ChagasWebmasterAuthor Commented:
Thank you @leakim!
you welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.