2012-03-29 8 views
0

selected text on divをマウスで選択してみてください。選択のために.select()メソッドを見つけました。しかし、それは私の問題を成し遂げていません。マウスで選択したテキストを検索するdiv jqueryで選択しますか?

私のようなものにしたい:私はマウスselection.iを使用してsimplyテキストを選択したとき

<div id='mydiv'>Lorem Ipsum is simply dummy text of the printing.</div> 

jqueryを使用してそれを見つけました。 または他に何か別のものを選んで取得したい。

答えて

2

あなたはそれを選択する必要はありません。 クリックハンドラを追加するだけです。

document.addEventListener('touchend', handleTouchEnd, false); 
function handleTouchEnd(e){ 
    console.log(e.target.innerHTML);// returns whatever is there in the div 
    console.log(e.target.textContent);// better option, as it returns text only 
} 
関連する問題