Solved

Quick javascript help

Posted on 2014-12-12
6
79 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…

789 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