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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:40:25+00:00 2026-05-16T04:40:25+00:00

For standard browsers you can use something like this to change the coloring of

  • 0

For standard browsers you can use something like this to change the coloring of selected text:

div.txtArea::selection {
 background: transparent;
}

div.txtArea::-moz-selection {
 background: transparent;
}

div.txtArea::-webkit-selection {
 background: transparent;
}

But I need to do this with JavaScript instead.

My users can select text and then change the color. While they are selecting another color it updates the color constantly. Since the text is selected they can’t see what the color looks like. I need to change the selection style of my targeted element to be transparent only during mouseover of the color changer.

I have tried a few things including:

$('div.txtArea').css({
    'selection': 'transparent',
    '-moz-selection': 'transparent',
    '-webkit-selection': 'transparent'
});

Is there a way to do this with javascript?

  • 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-16T04:40:25+00:00Added an answer on May 16, 2026 at 4:40 am

    There’s no DOM interface for manipulating pseudo-classes. The only thing you can do is add the rules to a stylesheet. For instance:

    // Get the first stylesheet 
    var ss = document.styleSheets[0]
    
    // Use insertRule() for standards, addRule() for IE
    if ("insertRule" in ss) {
        ss.insertRule('div.txtArea::-moz-selection { background: transparent; }', 0);    
        ss.insertRule('div.txtArea::selection { background: transparent; }', 0);    
        ss.insertRule('div.txtArea::-webkit-selection { background: transparent; }', 0);    
    }
    

    You can access and change rules using stylesheet.cssRules[index].style, stylesheet.rules[index].style for IE, which is where it gets a little more complicated.

    I didn’t include an IE6-8 example using addRule() because those versions of IE don’t support ::selection.

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

Sidebar

Related Questions

Is there any javascript plugin/library/script that will can transform a standard PHP to use
Do browser vendors optimize against jQuery? I know this sounds absurd anti-standard, but I
I am looking for a Standard Inheritance System that can work in both node.js
I have a few div boxes that are using position:fixed and I use a
I would like to set a specific cookie domain for my cookies, because this
In modern browsers, jQuery makes use of document.querySelectorAll() to boost performance when valid CSS
I've search and can't find a solution. Hopefully I'm overlooking something simple. What I'm
I am given a function like this: //! Work on record. /*! \param[in] Record
I know I can save a canvas to PNG file easily with modern browsers.
I have a standard HTML login page, which I would much rather use than

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.