1

I just wanted to do so on function

function changeGenre(toWhat) {
    [...]
    $('::selection').css("background-color",'rgb('+color+')');
}

But it doesn't seem to work. Why?

EDIT: ::selection isn't a DOM element, so I'm looking for alternative way of solving this.

Kajcioch
  • 175
  • 1
  • 8
  • where is `color` variable decalred ? where is your html ? where and how you call `changeGenre` ? – elreeda Apr 16 '16 at 09:15
  • I used `[...]` to not show you a whole function for no reason. Color is declared and is used many times in my code and it works. For example, in same function, I've got `$('.cover').css("background-color","rgb("+color+")");` and it works. Also, the `changeGenre` is called on button click, which has `onclick` attribute @John – Kajcioch Apr 16 '16 at 09:23

1 Answers1

1

Try Using it with css class:see this post:Set the text selection color with jQuery. Demo not working

$(document).ready(function(){
 changeGenre();
});

function changeGenre() {
    $('p').addClass("gr");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<style>
p.gr::selection {
    background:#ff0099;
}
</style>

<p><strong>Note:</strong> ::selection is not supported in Internet Explorer 8 and earlier versions.</p>
Community
  • 1
  • 1
Suchit kumar
  • 11,809
  • 3
  • 22
  • 44