Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery double click, but don't select the content

Tags:

jquery

I'm using jquery's dbclick() function in order to toggle highlight of the table raw. The problem I'm facing is that whenever I double click the content of the cell is also selected. Is there an easy way to prevent content selection?

My code:

if ($('.tbl_repeat').length > 0) {
    $('.tbl_repeat tr').dblclick(function() {
        $(this).toggleClass('tr_active');
    });
}

Perhaps I didn't make myself clear - I don't want to disable selecting all together - only when the double click occurs - apart from this event everything else should be selectable as usual.

like image 216
user398341 Avatar asked Dec 10 '22 08:12

user398341


2 Answers

You can try to deny selection via css on element what you doubleclick

.unselectable {
   -moz-user-select     : none;
   -khtml-user-select   : none;
   -webkit-user-select  : none;
   -o-user-select       : none;
   user-select          : none;
}
like image 162
Larry Cinnabar Avatar answered Dec 29 '22 17:12

Larry Cinnabar


Place the below coding between here (between Head Tags)

<style>
        .unselectable {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -o-user-select: none;
            user-select: none;   
        }
    </style>

Put this in between here (between Body Tags)

<p class="unselectable"> your unselectable text here </p>

Just like this..

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .unselectable {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -o-user-select: none;
            user-select: none;   
        }
    </style>
</head>
<body>
    <p class="unselectable">
    <span> your unselectable text here </span><br>
    <a href="#" onclick="return false;"> your unselectable link here </a></p>
</body>
</html>​
like image 31
RJ Style Avatar answered Dec 29 '22 19:12

RJ Style