jQuery plugin to disable text selection on elements

It took my a while to find a bit of script that worked cross browser, but the jquery plugin at http://code.jdempster.com/jQuery.DisableTextSelect/ does the job!

When working on the UI of a web application text would often get selected by the browser incorrectly, for example while dragging an element, or clicking on an element with an onclick event.

If you are using jquery already; download it, include it, then use:

$(‘.elementsToDisableSelectFor’).disableTextSelect();

If you need this functionality without including the whole of jquery, take a look at the source code for the plugin. It’s only about 20 lines long. It uses a different method for Firefox and Internet Explorer, with a fallback for everything else but it should be easy to convert in to native JS or another javascript framework.

This entry was posted in Googled, Web dev and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

7 Comments

  1. Posted October 9, 2009 at 10:06 pm | Permalink

    The link to your script is broken.

  2. shableep
    Posted December 12, 2009 at 2:05 am | Permalink

    Sweet. Wonder why more people aren’t using this. Really helps break the line between app and document.

  3. Hussain
    Posted December 12, 2009 at 5:40 pm | Permalink

    Hi friend,
    How to use this jquery to disable text selection. Please tell me.

  4. Posted July 15, 2010 at 12:39 pm | Permalink

    Thanks a lot!

    I just plugged it into my color selector plugin and it works just great. :)

  5. Yury
    Posted October 11, 2010 at 6:24 pm | Permalink

    Thanks! That’s working well! And this plugin doesn’t prevent observing click event, what was critical for me.

  6. Posted October 31, 2010 at 5:25 pm | Permalink

    Very neat script, very clever. This would work very well for preventing people stealing your content, but it is obviously not a fool proof solution, but nothing is!

  7. Posted March 30, 2011 at 3:11 pm | Permalink

    It’s a really great and useful plugin! Thanks

One Trackback

  1. By Anonymous on September 8, 2010 at 10:40 pm

    [...] [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

  • Categories

  • Archives