$(document).ready(function () {
$("#btnhighlight").click(function () {
alert("yes");
var htext = $("#txthighlighttext").val();
$("#lstCodelist option").each(function () {
var sp = $(this).text();
var sp1 = sp.split(' ');
$.each(sp1, function (i, l) {
if (l == htext) {
l.css('color', 'yellow');
}
});
});
});
});
var x = “hello world”;
I need to change the text color on l. that is suppor I got the text from the string “hello”.
css(
Can I do l.('color', 'yellow'); I am getting javascript error.
if I do like this $(this).css('color', 'yellow'); Nothing happening.
thanks
Try:
$(l).css('color', 'yellow');Edit:
Ok…you are working with strings and not actual DOM elements. My suggestion is to dynamically place
linto an element like<span>and apply the CSS to that and then replace the original text in the DOM. I actually did something similar to this a while back:http://www.randomsnippets.com/2008/03/07/how-to-find-and-replace-text-dynamically-via-javascript/
I’m not saying this is the perfect solution but it will lead you down the right path.