tonelm54
asked on
selection highlight
Is it possible to highlight text in jQuery via code?
Im trying to do my own autocomplete, and want to 'autocomplete' the text box with some text, so if the user presses a key then the highlighted text disappears.
What Im trying to do is set the highlight range, such as:-
Also I need to know what text is not highlighted, such as:-
My issue is I cannot find out any way of setting or getting highlighted text.
Im trying to do my own autocomplete, and want to 'autocomplete' the text box with some text, so if the user presses a key then the highlighted text disappears.
What Im trying to do is set the highlight range, such as:-
$('#txtTest').keyup(function () {
var currLen = $('#txtTest').val();
$('#txtTest').val($('#txtTest').val() + " Hello");
$('#txtTest').attr({
selectionStart: currLen,
selectionEnd: 999
});
});
So if you put in Bob in the textbox, then it will return 'Bob Hello' with ' Hello' highlighted.Also I need to know what text is not highlighted, such as:-
$('#txtTest').keyup(function () {
var currUnselectedText = $('#txtTest').val().substring(1,$('#txtTest').selectionStart());
});
});
My issue is I cannot find out any way of setting or getting highlighted text.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.