0

Is there any way to differentiate between clicking a div element and selecting its content,

What I am looking for is to trigger click action only if the div was clicked but not when its contents were selected

<div onClick="funA">
    Allow content to be copied if selected, else perform funA when clicked
</div>

Current onClick behavior triggers when I try to select the content and copy it, as soon as i unpress the click, But I want to not trigger funA or detect its selected and control it somehow. I hope the question is clear enough, else I will add more specifics to the quesiton.

Pratyush Dhanuka
  • 1,405
  • 2
  • 11
  • 21

2 Answers2

0

you can see the difference this way :

<div id='click'>
    Allow content to be copied if selected, else perform funA when clicked
</div>
$('#click').click(function() {
    var sel = getSelection().toString();
    if(!sel){
        alert("clicked");
    }
});​
Rahele Dadmand
  • 573
  • 1
  • 4
  • 17
0

Refering to Preventing click event with jQuery drag and drop using $("#element").click(function(mouseEvent){ // click event }); will not execute when the mouse is dragged and dropped.

$("#funA").click(function(mouseEvent){  });

<div id="funA">
    Allow content to be copied if selected, else perform funA when clicked
</div>
kapuetze
  • 35
  • 1
  • 8