Alterar CSS do texto selecionado usando Javascript

Estou tentando criar um bookmarklet javascript que funcione como marcador, alterando o plano de fundo do texto selecionado em uma página da Web para amarelo quando o bookmarklet for pressionado.

Estou usando o código a seguir para obter o texto selecionado e ele funciona bem, retornando a string correta

function getSelText() {
var SelText = '';
if (window.getSelection) {
    SelText = window.getSelection();
} else if (document.getSelection) {
    SelText = document.getSelection();
} else if (document.selection) {
    SelText = document.selection.createRange().text;
}
return SelText;

}

No entanto, quando criei uma função semelhante para alterar o CSS do texto selecionado usando o jQuery, ele não está funcionando:

function highlightSelText() {
var SelText;
if (window.getSelection) {
    SelText = window.getSelection();
} else if (document.getSelection) {
    SelText = document.getSelection();
} else if (document.selection) {
    SelText = document.selection.createRange().text;
}
$(SelText).css({'background-color' : 'yellow', 'font-weight' : 'bolder'});

}

Alguma ideia?

questionAnswers(6)

yourAnswerToTheQuestion