Quick javascript help


I need to add <span>*</span> for each character in the 'info' variable.

It is close but I can not figure out how to get the second function to edit the info variable and save it so I can write it later.

info = "<div class=\daysz\">Days<div class=\"infoz\">" + daysLeft + "</div></div><div class=\daysz\">Hours<div class=\"infoz\">" + hrsLeft +"</div></div><div class=\daysz\">Minutes<div class=\"infoz\">" + minsLeft + "</div></div>";

var words = $(".infoz").text().split("");
$.each(words, function(i, v) {
Who is Participating?
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.

HainKurtSr. System AnalystCommented:
for each character???

<div class="daysz"...

>>> like this? does not make sense...

<<span>*</span>d<span>*</span>i<span>*</span>v<span>*</span> <span>*</span>c<span>*</span>l<span>*</span>a<span>*</span>s<span>*</span>s<span>*</span>=<span>*</span>"<span>*</span>d<span>*</span>a<span>*</span>y<span>*</span>s<span>*</span>z<span>*</span>"<span>*</span>...
movieprodwAuthor Commented:
Each character in the .infoz not the whole thing.

I have it like this Days 90 but I want to make a box around each one for countdown styling so I need it to be:

<div class="daysz">Days<div class="infoz"><span>9</span><span>0</span></div></div>
movieprodwAuthor Commented:
If you want to help me just work with the variable that is great too.

split: daysLeft
append: <span>
save as: daysLeft
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.

HainKurtSr. System AnalystCommented:
try this:

var daysLeft = 10;
var hrsLeft = 14;
var minsLeft = 34;

info = "<div class=\"daysz\">Days<div class=\"infoz\">" + AddSpans(daysLeft) + "</div></div><div class=\"daysz\">Hours<div class=\"infoz\">" + AddSpans(hrsLeft) +"</div></div><div class=\"daysz\">Minutes<div class=\"infoz\">" + AddSpans(minsLeft) + "</div></div>";

function AddSpans(s){
    return "<span>" + s.toString().split("").join("</span><span>") + "</span>";


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
movieprodwAuthor Commented:

Seriously sat here for over an hour, thank you.
HainKurtSr. System AnalystCommented:
just note that I also fixed your info variable... you missed out lots of ", like below:

info = "<div class=\"daysz\">Da...
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

From novice to tech pro — start learning today.