I am very new to jQuery, and have recently converted one javascript function to jQuery. The purpose of the code is to select text input by the user in `target` text input within `sentence` div. **Javascript** getSelection = function(){ sentence = document.getElementById("sentence"); target= document.getElementById("target"); selection = window.getSelection(); range = document.createRange(); index = sentence.innerHTML.indexOf(target.value); range.setStart(sentence.firstChild,index); range.setEnd(sentence.firstChild,(index + target.value.length)); selection.removeAllRanges(); selection.addRange(range); } **jQuery** $(document).ready(function(){ $("#getSelection").click(function(){ sentence = $("#sentence")[0]; target= $("#target")[0]; selection = window.getSelection(); range = document.createRange(); index = sentence.innerHTML.indexOf(target.value); range.setStart(sentence.firstChild,index); range.setEnd(sentence.firstChild,(index + target.value.length)); selection.removeAllRanges(); selection.addRange(range); }); }); **Additional Info** This function is part of a small utility that mimics click and drag for selection of text. complete code is available on my [github repo][1]. Following is the screenshot of the utility. [![Screenshot of the utility][2]][2] **Question** Having little knowledge of jQuery I am concerned whether I am doing everything right?, please let me know. [1]: https://github.com/beyond2013/textSelection.git [2]: https://i.sstatic.net/PlYpt.png