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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:38:20+00:00 2026-05-23T09:38:20+00:00

Hello Stackoverflow family :) I’m in need of a simple jQuery script, but since

  • 0

Hello Stackoverflow family 🙂

I’m in need of a simple jQuery script, but since I’m a beginner in jQuery yet.. Then I cannot figure this out myself 🙁 And there is no such script yet or I just don’t know the correct term to search.

Idea is very simple. My designer designs h1 tags with two colors. For example: “Why use mysite.com?” then [mysite.com?] is with different color. I can see the technical solution as being triggered by $(“h1.title”) and the script would calculate how many words there are. Then divide by 2 and make one half different color with append container around them or something.

How to make this happen?

Kalle

  • 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-05-23T09:38:20+00:00Added an answer on May 23, 2026 at 9:38 am

    If you really want to use JavaScript to do this, see this fiddle for an example of a method for colouring the second half of the text of an element differently.

    It does it by splitting the original string on spaces, determining the halfway point, and then rebuilding the string with a span (with whatever styles you like applied to it) around the second half:

    $("h1").each(function() {
        var t = $(this).text();
        var splitT = t.split(" ");
        var halfIndex = Math.round(splitT.length / 2);
        var newText = "";
        for(var i = 0; i < splitT.length; i++) {
            if(i == halfIndex) {
                newText += "<span style='color:#ff0000'>";
            }
            newText += splitT[i] + " ";
        }
        newText += "</span>";
        $(this).html(newText);
    });
    

    I’m sure there’s a quicker way of doing this, but this is the first thing that came to mind.

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

Sidebar

Related Questions

Hello stackoverflow community ! I am trying to figure out how to architect my
Hello stackoverflow contributors! I have this script that gets the starting position of my
Hello helpful stackoverflow members, I'm trying to accomplish what seems to be a simple
Hello Stackoverflow community, for a little game I need to display an octagon (
Hello again stackoverflow! So i build this script: <?php $xmlurl = 'http://api.ipinfodb.com/v2/ip_query.php?key=apikey&ip=127.0.0.100&timezone=false'; $xml =
Hello people from StackOverflow! I come to you with yet another question. :) As
Hello fellow stackoverflow family members? I know it is un-efficient to create one extra
Hello StackOverflow'ers, I have a (flex) app that, on the click of a button,
Hello StackOverflow community, Using Google App Engine, I wrote a keyToSha256() method within a
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];

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.