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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:16:59+00:00 2026-05-26T01:16:59+00:00

I trying to compare the styles of elements on my page. But one element

  • 0

I trying to compare the styles of elements on my page. But one element dynamically changes it’s text color to red, but represented as a rgb value. And the other element (to compare it with) uses #123456 values. Is there a converter somewhere that can take rgb and turn it into #number?

For example:

#000 instead of rgb(0, 0, 0)

  • 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-26T01:17:00+00:00Added an answer on May 26, 2026 at 1:17 am

    People always forget that rgb colors can be expressed as percentages, as well as integers.

    function rgbToHex(rgb){
        var i= 0, c, hex= '#',
        rgb= String(rgb).match(/\d+(\.\d+)?%?/g);
        while(i<3){
            c= rgb[i++];
            if(c.indexOf('%')!= -1){
                c= Math.round(parseFloat(c)*2.55);
            }
            c= (+c).toString(16);
            if(c.length== 1) c= '0'+c;
            hex+= c;
        }
        return hex;
    }
    
    
    
    
    alert(rgbtohex('rgb(255,127,0)')+'\n'+
    rgbtohex('rgb(100%,50%,0)'));
    
    /*  returned value: 
    #ff7f00
    #ff7f00
    */
    

    // also works with arrays-
    rgbToHex([100,200,60])

    // returned value: #64c83c

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

Sidebar

Related Questions

Im trying to compare these two chars but on win 32 Visual Studio 2008:
I'm trying to compare the differences between jQuery and JavaScript in a project, but
I am trying to compare a one dimensional array in a collection of 1
Trying to compare voids for a sorting algorithm. I have this so far but
I am trying two compare two strings in JavaScript. But I guess there is
I am trying to change a element background color according the the progress of
I'm trying to compare an MD5 checksum generated by PHP to one generated by
I am trying to compare two PHP projects using PHP Depend (http://pdepend.org). One is
Trying to compare and print only members with Inactive status. The problem is that
When trying to compare software versions 5.12 to 5.8, version 5.12 is newer, however

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.