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 8512019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:10:02+00:00 2026-06-11T04:10:02+00:00

I am currently using this JavaScript to change the color of the second word

  • 0

I am currently using this JavaScript to change the color of the second word in each of my widget titles. But with this code, as it loops through each widget, it ends up printing all of the titles, from all of the widgets on the page, in each widget title. So for example, I have two widgets with titles “Recent Work” and “Recent Press”. Work and Press are supposed to be orange. With this code, it outputs “Recent WorkRecent Press”, where Work and Recent are both orange. This is printed the same in both widget titles. How can I edit this so it makes just the second, or last since each title will only be two words long, word orange?

var split = $("h4.widgettitle").text().split(" ");

if(split.length > 0) {
$("h4.widgettitle").html('').append("<span class='firstWord'>" + split[0] + "<span> ");

if(split.length > 1) {
    $("h4.widgettitle").append("<span class='secondWord'>" + split[1] + "<span> ");
    for(var i=2;i<split.length;i++) {
        $("h4.widgettitle").append(split[i] + " ");
    }
  }
}
  • 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-11T04:10:04+00:00Added an answer on June 11, 2026 at 4:10 am

    Quickest way:

    $('h4.widgettitle').each(function(){
    
        var text = $(this).text().split(' ');
        if(text.length < 2)
            return;
    
        text[1] = '<span class="secondWord">'+text[1]+'</span>';
    
        $(this).html( text.join(' ') );
    
    });
    

    See it running

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently am using this JavaScript code snippet to select 3 checkboxes at a
I am currently using this code to grab key-strokes, but I am missing e.g.
Currently I'm using this minor bit of javascript to remove a small list of
I'm currently using this code (per the codex) to show children on parent pages,
I'm currently using this code to calculate the sunrise / sunset times. (To be
I am currently using this code to get data from a URL: NSURL *url
how can I change the background color of current element using plain javascript? for
I am currently using the following JavaScript code: concatedSubstring.replace(/\//g, '-').replace(/[A-Za-z]/g, function(c){ return c.toUpperCase().charCodeAt(0)-64; });
Im currently using Code Igniter to have pretty URLs, and I have this system
I'm currently using this compare options to sort a list of strings: [self compare:aString

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.