Here is my code, I want to select words on mouseup, except some div by id.
I have tried:
$("body:not(#protect)").mouseup(function() {
$("body").not("#protect").mouseup(function() {
$("body:not('#protect')").mouseup(function() {
But the not.selection not working for the $('body').mouseup.
BTW, in my main page, the selection area not only the div#content-area, just for the question, I left one div for test.
So what is the best way to protect one div out of the whole body mouseup by jquery? Thanks.
Since
mouseupevents bubble, you can just select the<div>then selectively filter out events from#protectedusinge.stopPropagation()to stop the bubbling. See jsFiddle.You could cancel the selection, too.
P.S. You should use
obj.toString()orString(obj)instead ofnew String(obj).