Reputation: 1467
I need color the selected row with jquery. Suppose I have a textarea which there are into a line. I need tp color the line that was clicked when the user click on the textarea. So I use this code:
$(document).on("mouseup", '#scroll_bar', function(eventData) {
console.log("DELLLLLLLLL");
var scrollPosition = $(this).scrollTop()
var lineHeight = $(this).css("line-height");
lineHeight = parseInt(lineHeight.substring(0, lineHeight.length - 2));
var line = Math.floor((eventData.offsetY + scrollPosition) / lineHeight);
alert($(this).val().split("\n")[line]);
});
But I find the line that the user clicked but I don't how selected with a color like orange. Anyone can help me?
Upvotes: 0
Views: 955
Reputation: 249
It's possible to color one (or more) line(s) of the textarea with a background-image.
Here you have an example how you can do it with linear-gradient as background-image.
background: linear-gradient(to bottom, #fff 0px, red 0px, red 22px, #fff 22px);
background-position: 20px;
Upvotes: 3