-5

I have a blog and blog titles are like this;

"Hey There: Part 1"

So, is there any chance to break the line after ":", because I want Part 1 to start a new line. So it should be like this:

"Hey there:

Part 1"

But there are so many titles, so I want to do this with a javascript code to all of those titles. Is this possible?

K. Ayaz
  • 21
  • 6

4 Answers4

1

You can use split() of JavaScript

var text = "Hey There : Part 1";
var newText = text.split(":").join('\n');
alert(newText);
Hardik Pithva
  • 1,729
  • 1
  • 15
  • 31
0

Using jQuery:

var blogTitle = $('theTitleElement')
$(blogTitle).each(function(){
   $(this).html(this.textContent.split(':').join('<br>'))
});
Jai
  • 74,255
  • 12
  • 74
  • 103
0

%0D%0A are the characters for a carriage return and line break if you're URL encoding.

%0D is a carriage return character %0A is a line break character.

If you want to line break in your JavaScript code then you can use \n to escape a line break.

Hardik Pithva
  • 1,729
  • 1
  • 15
  • 31
Nse
  • 305
  • 4
  • 21
0
var sOrig = "Hey There: Part 1";
sOrig.split(':').join('\n');

you can replace the \n with html etc if needed or just do a replace()

Hardik Pithva
  • 1,729
  • 1
  • 15
  • 31
Rich
  • 970
  • 2
  • 16
  • 42