Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:53:42+00:00 2026-06-11T05:53:42+00:00

An interesting little problem… Trying to loop through the children of a paragraph (words)

  • 0

An interesting little problem…

Trying to loop through the children of a paragraph (words) and color them, one by one.

Here’s a hard coded working version with words in separate elements:
http://jsfiddle.net/JjRHT/25/

using

window.setInterval(function(){
$(".item:nth-child(1)").css("color", "#FFFFFF");
}, 1000);

just to show what I’m attempting…obviously not the way to go!

so – can I select each child of a paragraph? and how do I do the loop properly – with a small delay…

steven

edit:

I found a jquery plugin that splits text into words nicely ready for css:

<p class="word_split">Don't break my heart.</p>
<script>
$(document).ready(function() {
  $(".word_split").lettering('words');
});
</script>

Which will generate:

<p class="word_split">
  <span class="word1">Don't</span>
  <span class="word2">break</span>
  <span class="word3">my</span>
  <span class="word4">heart.</span>
</p>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:53:44+00:00Added an answer on June 11, 2026 at 5:53 am

    The main problem here is that you can’t apply styles to words of a paragraph.

    If you want to color words (and not the whole element), you’ll have to extract the words from the paragraph.

    This cuts the paragraph in two parts, and gives a different color to each part :

    var tokens = $paragraph.text().split(' ');
    var i=0;
    window.setInterval(function(){
           i = (i+1)%tokens.length;
           $paragraph.html( '<span class=onecolor>'+tokens.slice(0, i).join(' ')+'</span>'
               + ' <span class=othercolor>'+tokens.slice(i, tokens.length).join(' ')+'</span>');
    }, 1000);​
    

    Demonstration : http://jsfiddle.net/CcBLr/1/


    EDIT :

    Supposing you want to make specific things on your words (as you say, different delays for example), you could do this for the preparation :

    var tokens = $paragraph.text().split(' ');
    var spans = tokens.map(function(t){return '<span>'+t+'</span>'});
    $paragraph.html(spans.join(' '));
    var $words = $paragraph.children('span');
    

    $words is now a collection of the words of the paragraph but you may apply styles on them. for example with this :

    $words.each(function(){
       var $word = $(this);
       setTimeout(
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, here's an interesting little problem I've had to deal with. I coded a
Interesting problem I have here, usually I just round up/down respectively for my needs
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
I've got a real little interesting (at least to me) problem to solve (and,
There is an interesting problem at hand. I have a role-playing MMOG running through
I'm having an interesting but difficult problem with my JavaScript code. Basically, I'm trying
Came across an interesting little problem at work yesterday. This is a question about
Here is an interesting optimization problem that I think about for some days now:
I have a interesting problem in Java, its a little wordy though so bear
I have an interesting little problem, and I know there are multiple ways to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.