3

My JSON output currently looks like this:

"description":"MUSIC VIDEO - 7:13\n\nCREDITS\n\nLabel: Black Pain Records\nProduction Company: Idyll Films 

I have this bit of jQuery to fetch and input as text:

$.getJSON("http://vimeo.com/api/oembed.json?url=http://vimeo.com/"+strip2+"&callback=?", function(json){ $('.creditText').text(json.description); }); 

strip2 is my vimeo id. Currently the output is all one line, I would like where the \n is to be converted into
tags, is this possible?

3 Answers 3

7

you could do

json.description.replace(/\n/g, '<br/>') 
Sign up to request clarification or add additional context in comments.

1 Comment

You need a regular expression, otherwise only the first occurrence will be replaced.
4

Try to replace the line $('.creditText').text(json.description); with:

$('.creditText').html(json.description.replace(/\n/g, "<br/>"); 

Please note that you need to change text() to html() so the <br/> elements will be inserted as HTML and shown on the page.

See the code.

1 Comment

can we use prepend or append instead of html? these two functions does the same thing
0

use replace function of java-script for this...

$.getJSON("http://vimeo.com/api/oembed.json?url=http://vimeo.com/"+strip2+"&callback=?", function(json){ $('.creditText').text(json.description.replace('\n','<br>')); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.