Solved

Quick javascript help

Posted on 2014-12-12
6
76 Views
Last Modified: 2014-12-12
Hello,

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("");
$(".infoz").empty();
$.each(words, function(i, v) {
    $(".infoz").append($("<span>").text(v));
});
==
0
Comment
Question by:movieprodw
  • 3
  • 3
6 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40496813
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>...
0
 
LVL 1

Author Comment

by:movieprodw
ID: 40496838
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>
0
 
LVL 1

Author Comment

by:movieprodw
ID: 40496841
If you want to help me just work with the variable that is great too.

split: daysLeft
append: <span>
save as: daysLeft
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40496865
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>";
}

alert(info);

Open in new window

0
 
LVL 1

Author Closing Comment

by:movieprodw
ID: 40496891
THANK YOU!

Seriously sat here for over an hour, thank you.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40496909
just note that I also fixed your info variable... you missed out lots of ", like below:

info = "<div class=\"daysz\">Da...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now