I got a variable using document.getSelection()
This variable is well displayed if I use alert()
but not if I use html()
.
How can I make it visible with html()
?
$(document).ready(function(){
$(".sentence").dblclick(function(){
var selected_word = document.getSelection();
$("#word_to_be_showned_in").html(selected_word);
alert(selected_word);
});
});
<p class="sentence">have a try</p>
<p>Selected word should appear here: <span id="word_to_be_showned_in">XXX</span></p>
Example (compatible with chrome): http://js.do/code/38012
getSelection()
returns an object, not a string. Add .toString()
to get its text:
var selected_word = document.getSelection().toString();
$("#word_to_be_showned_in").html(selected_word);
alert(selected_word);
Fixed example: http://js.do/code/38017
I am trying to understand the code snippet to create tabs dynamically in my asp.net web application. I am a novice in JQuery, I understood that "tabsDiv.tabs("add", '#main', pages[i][0]);" is ...
I am trying to understand the code snippet to create tabs dynamically in my asp.net web application. I am a novice in JQuery, I understood that "tabsDiv.tabs("add", '#main', pages[i][0]);" is ...
I have one drop-down its contain DataType. and one text-box this this is for enter Regex Pattern. if I am enter /test/ in textbox. or select from drop-down Int then its wrong pattern if enter in ...
I have one drop-down its contain DataType. and one text-box this this is for enter Regex Pattern. if I am enter /test/ in textbox. or select from drop-down Int then its wrong pattern if enter in ...
I want to check if network connection exists at runtime in javascript. I am using window.navigator.onLine but its not working. <script language="javascript"> alert(window.navigator.onLine); &...
I want to check if network connection exists at runtime in javascript. I am using window.navigator.onLine but its not working. <script language="javascript"> alert(window.navigator.onLine); &...
I'm using a MacBook Air and have been looking into ePub creation. I've taken a copy of the epub3 boilerplate from github click here. I have in a javascript file added the following var txt = document....
I'm using a MacBook Air and have been looking into ePub creation. I've taken a copy of the epub3 boilerplate from github click here. I have in a javascript file added the following var txt = document....