score:1

Accepted answer

Google returned the following result: http://chris-barr.com/index.php/entry/disable_text_selection_with_jquery/

The code on that page is

$(function(){
    $.extend($.fn.disableTextSelect = function() {
        return this.each(function(){
            if($.browser.mozilla){//Firefox
                $(this).css('MozUserSelect','none');
            }else if($.browser.msie){//IE
                $(this).bind('selectstart',function(){return false;});
            }else{//Opera, etc.
                $(this).mousedown(function(){return false;});
            }
        });
    });
    $('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});

In this case, however, you can replace '.noSelect' with '.node', and it should disable text highlighting for all of your nodes.

score:0

If you do not want to disable selection of text completely (which is usually much nicer for the user), you can manually deselect an element via selectSubString.

.on("dblclick", function(d) { 
    toggle(d); update(d);
    var text = d3.select(this).select("text")[0][0]
    text.selectSubString(0,0)
});

But this does not yet work cross browser since the SVG API is not yet fully implemeted in many cases. (It works in Chrome at least)

A better cross browser way is to just rewrite the text. This usually also kills the selection:

g.on("dblclick", function(d) {
    toggle(d); update(d);
    var text = d3.select(this).select("text")
    var value = text.text()
    text.text(value)
})

This worked in Firefox and Chrome at least.


Related Query