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.

4 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. :)

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