Jump to content

How do I add the same string before each line?


Recommended Posts

An interesting one! I'm sure someone will come up with a better solution (RegExp test with a while loop that I couldn't quite manage...), but here's my idea:

<div id='the_text'>hello<br>dog<br />cat<br></div><script type='text/javascript'>var my_div = document.getElementById('the_text')var my_div_matches = my_div.innerHTML.split(/<br(.*?)>/i);for(i=0;i<my_div_matches.length;i++){	my_div.innerHTML = my_div.innerHTML.replace( my_div_matches[i] , "{1}" + my_div_matches[i] );}</script>

Obviously it's on a small scale - so don't know how it'll transfer into what you're doing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...