Mouseup doesn't fire on scroll bar for elements dynamically added (except Firefox):
CSS:
#dBox {
height: 100px;
width: 230px;
overflow - y: auto;
}
HTML:
<input type="text" id="s">
JQuery:
$(function() {
$('#s').focus(function() {
var $dbox = $('<ul id="dBox"></ul>');
for (i = 0; i < 10; i++) $dbox.append('<li>' + i + '</li>');
$(this).after($dbox);
$dbox.bind("mouseup", function() {
alert('in: ');
//console.log ('in: ');
});
});
});
// OR LIKE THIS
$('#s').focus(function() {
var $dbox = $('<ul id="dBox"></ul>');
for (i = 0; i < 10; i++) $dbox.append('<li>' + i + '</li>');
$(this).after($dbox);
});
$('#dBox').live("mouseup", function() {
alert('in: ');
//console.log ('in: ');
});
If you click anywhere on the ul
will fire BUT not on scroll bar. The same problem exists in all browsers except Firefox.
If you replace 'mouseup' with 'mousedown' will fire on scroll bar also, in all browsers.
After few more tests it seems that it doesn't make a difference if the 'ul' it's added dinamically or not, the mouseup just doesn't seem to recognize the scrollbar as part of 'ul' (except FF).
And the same problem if you replace 'ul' with 'div' and 'li' with 'p'.
<div id="dBox" class="" ><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>6</p><p>7</p><p>8</p><p>9</p></div>
$('#dBox').mouseup(function () {alert ('in: ');});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…