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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:17:01+00:00 2026-05-23T06:17:01+00:00

How to parse colors in text, if i type #40464f , i would like

  • 0

How to parse colors in text, if i type #40464f , i would like catch the color and apply it some CSS.

I know how to do that with added markup,

 <span data-color=""> #40464f </span>

for example.

But i would like to know if its possible to do that automatically without the needed to add markups manually ?

  • 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-23T06:17:01+00:00Added an answer on May 23, 2026 at 6:17 am

    Not really knowing what’s asked, I’ll just provide a way to match (HEX) colors within an HTML element.

    Given HTML:

    <p id="subject">
        Here is a color: #fff. Red is #ff0000 while #9ab57d is another color.
    </p>
    

    Use JS:

    $(function() {
        var m = $('#subject').text().match(/#(?:[0-9a-f]{3}){1,2}/gi);
        // ['#fff', '#ff0000', '#9ab57d']
    
        $.each(m, function(i, v) {
            // `v` is each color...
        });
    });
    

    (Demo)

    Update
    Demo where the colors are actually used:

    HTML:

    <p id="subject">
        Here is a color: #fff. Red is #ff0000 while #9ab57d is another color.
    </p>
    <ol id="result"></ol>
    

    JS:

    $(function() {
        var m = $('#subject').text().match(/#(?:[0-9a-f]{3}){1,2}/gi),
            $result = $('#result');
    
        $.each(m, function(i, v) {
            $('<li />').text(v).css('background-color', v).appendTo($result);
        });
    });
    

    Update #2
    Based on comments, replacing inline (demo):

    HTML:

    <p id="subject">
        Nous obtenons les 2 couleurs suivantes : #40464f &amp; #0f131a
    </p>
    

    JS:

    $(function() {
        var $subject = $('#subject'),
            str = $subject.html();
    
        str = str.replace(/#(?:[0-9a-f]{3}){1,2}/gim, "<span style=\"background-color: $&;\">$&</span>");
        $subject.html(str);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to parse a string such as p1=6&p2=7&p3=8 into a NameValueCollection .
I want to create a program that will parse text for key words and
I'm trying to use the Android Html.fromHtml method to parse a text like a
I'd like to parse a SOAPUI Project file and generate some documentation from the
I am attempting to parse a string like the following using a .NET regular
I want to parse a config file sorta thing, like so: [KEY:Value] [SUBKEY:SubValue] Now
I want to parse some HTML in order to find the values of some
I need to parse a string like February 12, 1981 as a Date. I
Hey. I'm trying to parse a CSS file using PHP. I'm trying to run
Is there any simple way to parse Ansi colors in log files, and use

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.