Wasim Shaikh
Wasim Shaikh

Reputation: 7030

How to change the selected text color In Internet explorer?

I have seen in many weblogs when we select text the background color of the text changes rather than usual blue. This Tech Works in Firefox and Safari, is there any method available for Internet Explorer?

Upvotes: 5

Views: 6801

Answers (5)

Jakob Sternberg
Jakob Sternberg

Reputation: 1859

This?

<style>
::selection {color:red;background:yellow;}
::-moz-selection {color:red;background:yellow;}
</style>

http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_selection

Upvotes: 1

Alex Williams
Alex Williams

Reputation: 151

You could always remove it.



    

        if (window.getSelection) {
          if (window.getSelection().empty) {  // Chrome
            window.getSelection().empty();
          } else if (window.getSelection().removeAllRanges) {  // Firefox
            window.getSelection().removeAllRanges();
          }
        } else if (document.selection) {  // IE?
          document.selection.empty();
        }

    


Upvotes: 0

alex
alex

Reputation: 490153

I think it would be difficult to emulate

  • You could try and set a background colour for the text selected, but the default blue highlighting will probably ruin your effect
  • The browser would probably choke on some systems when someone is selecting a lot of text and changing their selection rapidly.

I think you should use CSS for the browsers that support it, and wait patiently for IE to adopt this.

Upvotes: 0

cwj
cwj

Reputation: 2583

Not supported on IE as far as I know. Unless there's some clever hack I don't know about.

Upvotes: 0

Tyler Rash
Tyler Rash

Reputation: 1173

It can't be done in IE with pure CSS and I don't know of any pre-packaged JS that will get the job done, either.

Upvotes: 1

Related Questions