Nuha Khaled
Nuha Khaled

Reputation: 61

taphold Event to get selected word

How to use Taphold event in JQuery mobile to alert a specific word.

What I reach now gets the whole

tag content.

$("p").on("taphold",function(e){
    alert($(e.target));
});     

Upvotes: 0

Views: 79

Answers (1)

Nuha Khaled
Nuha Khaled

Reputation: 61

function get_selection() {
    var txt = '';
    if (window.getSelection) {
         txt = window.getSelection();
    } else if (document.getSelection) {
         txt = document.getSelection();
    } else if (document.selection) {
    txt = document.selection.createRange().text;
    }  
    return txt;
 }

 $(document).on("pagecreate","#pageone",function(){

 $(document).on("taphold",function(e){
     var select_text = get_selection();
     alert(select_text);
 });               
});

Upvotes: 1

Related Questions