javascript - Put line break in text string within a variable array in JS/jQuery -
noob question:
i have simple switch static text set switch @ interval , reason cannot line break work within string. i've tried few different methods of using \n or
, tried encoding , won't break string 2 sentences. see i'm doing wrong? text change working. trying string break new line "\n" located.
here's working fiddle:
script:
var texts = ["blah blah"+"\n"+"blah blah line two", "over 15,000 cups of"+"\n"+"starbucks drank daily!", "another awesome%0d%0aslogan here"]; var count = 0; function changetext() { $("#example").text(texts[count]); count < 3 ? count++ : count = 0; } setinterval(changetext, 500); html:
<div id="div-a"><h2><span id="example">over 15,000 eligible<br/>dealers nationwide</span></h2></div>
you using .text() input slogans.
i changed .text() .html() , put simple line breaks in sentences:
$(document).ready(function() { var texts = ["over 5,000 beers <br /> drank today", "over 15,000 cups of <br /> starbucks drank daily!", "another awesome<br />slogan here"]; var count = 0; function changetext() { $("#example").html(texts[count]); count < 3 ? count++ : count = 0; } setinterval(changetext, 500); });
Comments
Post a Comment