简体   繁体   中英

is there a way to change the background color when an user select text in browser ( for IE9 below versions)

We all know that when we select a text portion in browser, its background color changed to blue. I have used the ::selection pseudo-element to change the background color like below code.

::selection {
    background: pink;color: yellow;
}
::-moz-selection {
    background: pink;color: yellow;
}

see my example here but ::selection doesn't support for IE9 below versions.Please check the Browser compatibility table provided this page once. I need to apply the same properties in IE9 below versions. Can anyone tell me the alternate way for doing this one. Thanks in advance

one way you can do it with jquery

<script type="text/javascript">
$('document').ready(function(){
$("#textfield").focus(function () {
$('.class').css(' background-color','#ffe823');
});
});

<input type="text" class="class" name="textfield" id="textfield" >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM