0

I have a slider that allow the use to choose two values by dragging the slider.

I've added an onmouseup event to the div so that when the user finishes dragging, a function is called.

i.e.

    <div id="slider" onmouseup="myFunction()">
         Some code
    </div>

This works well in most instances. But if the user starts dragging and their mouse happens to be outside of the div when they finish (fairly common), the onmouseup event is not triggered.

Is there another event that would suit my needs?

I've tried using two events:

    <div id="slider" onmouseup="myFunction()" onmouseout="myFunction()">
         Some code
    </div>

But the events don't work together so the values gathered by the function flicker between the user specified values and the default (since they're called at different times).

I pretty much want onMouseUp to work if the click starts in the div but it can come 'up' anywhere. Any ideas?

SweetSour
  • 73
  • 1
  • 5
  • is this your slider ... or a slider component from a UI framework ? – lagbox Apr 27 '14 at 16:18
  • why not to append this events in js? and then you can use something like this $('body').mouseup(function(){ if (dragging){myFunction(); } }); – Artem Gorlachev Apr 27 '14 at 16:25
  • What @ArtemGorlachev mentioned, You're confusing the situation by using logic in the markup. Best to avoid the onwhatever events in HTML and assign them via JavaScript (`addEventListener()`). (@sukima continues his crusade against code logic in the markup.) – Sukima Apr 27 '14 at 16:44

0 Answers0