Insert element at text position of mouse click

Insert element at text position of mouse click

Hello,

I have a div like this:

Copy code
  1. <div id="primdiv">Hello World</div>

For this Ive bind the following code:

Copy code
  1. $("#primdiv").bind("contextmenu",function(e){
            if(e.which == 3){
                ......
            }//if
            return false;
        });

The if clause gets run when the user clicks with the right mouse button in the Text "Hello World" (= Works fine). Now I want to insert a new element at the position of the click. For example when the user clicks after the o of Hello the new div should look so (h1 as example):

Copy code
  1. <div id="primdiv">Hello<h1>big</h1> World</div>

Ived searched a lot and find many solutions with x and y coordinates. But none for just get the text position.

Does anyone have a answer on how to archive this?

Thanks in advance.