javascript - disableSelection on everything except input[type=text] - Stack Overflow

I am looking to use jQuery's "disableSelection()" function because I have a lot of drag

I am looking to use jQuery's "disableSelection()" function because I have a lot of drag and drop on the pages but I do not want to disable selection on input boxes, just everything else.

I have tried

$('body').disableSelection(); $('input').enableSelection();

$('body').not('input').disableSelection();

still DISABLES EVERYTHING ON THE PAGE. Thank you.

I am looking to use jQuery's "disableSelection()" function because I have a lot of drag and drop on the pages but I do not want to disable selection on input boxes, just everything else.

I have tried

$('body').disableSelection(); $('input').enableSelection();

$('body').not('input').disableSelection();

still DISABLES EVERYTHING ON THE PAGE. Thank you.

Share Improve this question edited Aug 18, 2011 at 14:57 Tim Joyce asked Aug 18, 2011 at 14:49 Tim JoyceTim Joyce 4,5176 gold badges36 silver badges50 bronze badges 6
  • What does "still no luck" mean? – Anthony Grist Commented Aug 18, 2011 at 14:53
  • it means, I tried what I said I tried and had no luck. – Tim Joyce Commented Aug 18, 2011 at 14:54
  • @Tim looking and no luck is not question buddy . Tell what happend what error you got what is not working – zod Commented Aug 18, 2011 at 14:55
  • I know what the term means in general; I don't know what it means in this particular case. You need to be specific about how those code snippets didn't work. What results do you get? Does it disable selection on everything? On nothing? – Anthony Grist Commented Aug 18, 2011 at 14:55
  • it's not a big deal, you just needed to ask and not be cryptic about your question either... – Tim Joyce Commented Aug 18, 2011 at 14:59
 |  Show 1 more ment

2 Answers 2

Reset to default 9

With

$('body').not('input').disableSelection();

You disable selection on every instance of body that is not an input. Since body is not an input this will just disable selection on body.

Try this:

$('body *').not(':has(input)').not('input').disableSelection();

However, like other people pointed out it's probably pretty useless disabling selection on things that aren't draggable in the first place. So maybe you should replace body with .drag or however you can select all the objects that are draggable (keeping the rest of the function the same).

I dont think so disableSelection will work for input textboxes. It's useful for making text elements, or elements that contain text, not text-selectable. For example, if you have a draggable element, you may not want text selection to occur when the user goes to drag the element.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744673467a4587186.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信