tags:

views:

97

answers:

3

How to change the background of a text When mousemove using jquery/Js?

I need text highlighting for each character when the mouse is moved, not for the entire div and I want the previous mouse over event should also be highlighted.

I am trying this on iphone safari browser. touchmove event is calling once not continuously.

A: 
$("#MyElementID").mouseover(function() { $(this).attr("background-color", "red");  } );

I think the above is about right.

or use something like from the jQuery site;

$("#MyElementID").hover(
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);
griegs
The first example should be `$(this).css("background-color","red");`. Note the `css()` call instead of the `attr()` call.
Bryan Ross
Hi Bryan Ross, thanks, but i need text highlighting for each character when the mouse is moved, not for the entire div.
Anish
@user440367 maybe you want to be more specific in your question as this is not clear.
griegs
+1 @Bryan Ross, yeah good pickup thanks.
griegs
hi griegs, for eg there is a <p>Lorem ipsum</p> When i move the mouse over the characters. it should be highlighted with any bg-color.
Anish
Are you saying as the mouse moves across a character, you want to be able to change the background color of that specific character?
Bryan Ross
yes, i want to change the background color of specific character
Anish
A: 

hi Ken Redler,

I am using touchmove event for text highlighting for mobile application,so plz give details regarding that.

Anish
+3  A: 

Is this more what you're looking for?

Bryan Ross
no, i want the previous mouse over event should also be highlighted.
Anish
My last attempt: http://jsfiddle.net/yCPZr/1/
Bryan Ross
Bryan, Thanks, it was working fine in browser when i changed the mouseenter into touchmove and trying this in device, it was not working
Anish