-2

I have some textboxes. I want to change their border-color to black on mouseover after mousedown. But when I mousedown and select the outer area from cells then mouseover fires without firing mousedown.

Here is a fiddle of the problem and here is my javascript:

var _mouseDown = false;

$( "input[id^='text']" ).mousedown(function() {
    _mouseDown = true;
});
$( "input[id^='text']" ).mousemove(function() {
    if ( _mouseDown ) {
        $(this).css("border-color","black")
    } 
});
$( "input[id^='text']" ).mouseup(function() {
    _mouseDown = false;
});
Popnoodles
  • 28,090
  • 2
  • 45
  • 53
Alok Sharma
  • 85
  • 1
  • 5

1 Answers1

0

Reference, this will help you

Try this one

var _mouseDown = false;
$( document ).mousedown(function() {
    _mouseDown = true;
});
$( "input[id^='text']" ).mousemove(function() {
    if ( _mouseDown ) {
        $(this).css("border-color","black");
    } 
});
$( document ).mouseup(function() {
    _mouseDown = false;
});

Here is the sample JSBin

Community
  • 1
  • 1
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
  • Thank u Naveen , it resolved my issue . i was using input id in mouse up function instead of document due to which cells used to get selected as black border color on mouseover without mousedown – Alok Sharma Aug 26 '15 at 13:08