Say I have an ul
(li
) list in the page:
<ul>
<li>xxx<li>
<li>xxx<li>
</ul>
The element li
are clickable and double-clickable, they are attached with these events, and I return false
in both of them.
$('ul li').on('click',function(){
//do what I want
return false;
}).on('dblclick',function(){
//do what I want
return false;
});
But when the user double-clicks the element, the text inside the li
will be selected. How can this be prevented?
Update:
Solved now,I use the following code with the css selector by NiftyDude:
$('ul li').on('click',function(){
//do what I want
return false;
}).....on('dragstart',function(){return false;}).on('selectstart',function(){return false;});
e.preventDefault()
instead ofreturn false
. – Jutreturn false;
is the same as calling bothpreventDefault()
andstopPropagation()
on the event handler arg. Perhaps the best thing to do, though, would be to just passfalse
directly:/*....*/.on('dragstart selectstart', false);
– Track