Question: As an example that we have

Name : Abdul Naeem

if we select the Naeem from above so to get Abdul From it.......

is it possible to get the left side words of the selected words

i tried but i have not found this..... can any body help me out of this problem.

i found some tips where it only get the selected words but i need the words on its left side

[Get the Highlighted/Selected text](https://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text)

for example lets consider if an object weighs 30 N. now i want to select the 30, and get the word weighs from it ?? how can i do it in javascript –

Answer: 
It is nontrivial, mainly because of the hierarchical nature of the document.

A restricted functionality which will get you the previous word *as long as it is in the same element*, in non-IE browsers:

```
// get the selection
var sel = window.getSelection();
// get the element in which the selection is made, and the start and end position
var node = sel.anchorNode;
var from = sel.anchorOffset;
// let's see what's before the selection
var textBeforeWord = node.textContent.substring(0, from);
var match = textBeforeWord.match(/(\w+)\s+/);
var previousWord = match[1];

```

This gets much more complicated when you consider the possibility that a word could be the first thing in its element, or that a selection might be across elements, when you would need to navigate the DOM hierarchy to hunt the previous element. It is also complicated by the fact that you would need to do it twice, completely differently (since IE's API is totally different).

**EDIT** In case of a `<textarea>` element, it gets much simpler, as you don't need to worry about the selection spilling over the element. For IE you will have to do some gymnastics, since it does not support `selectionStart`, as described [here](https://stackoverflow.com/questions/263743/caret-position-in-textarea-in-characters-from-the-start).

```
var node = document.getElementById('mytextarea');
var from = node.selectionStart;
var textBeforeWord = node.textContent.substring(0, from);
// the rest is the same as above

```
Try This in JS with Jquery : 

```
var a="Name : Abdul Naeem";
var sp="Naeem";
$(function(){
var x=a.split(sp);
    z=x[0].split(" ");
    alert(z[z.length-2]);
});

```

[Demo in JSFIDDLE](http://jsfiddle.net/p1zLx4t0/1/)