Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see you're using Rangy, but I don't how to use it at all. Before I realized what Rangy was, I looked up how to get the current selection. I found a function that gets it and replaces it with a passed in value. I ended up modfiying it, but here it is:</p> <p><a href="http://jsfiddle.net/fjYHr/1/" rel="nofollow">http://jsfiddle.net/fjYHr/1/</a></p> <pre><code>$(document).ready(function () { $("#setlink").click(function () { replaceSelectedText("jumplink"); }); }); function replaceSelectedText(nameValue) { var sel, sel2, range; if (window.getSelection) { sel = window.getSelection(); sel2 = ""+sel; // Copy selection value if (sel.rangeCount) { range = sel.getRangeAt(0); range.deleteContents(); var newA = document.createElement("a"); newA.name = nameValue; newA.innerHTML = sel2; range.insertNode(newA); } } else if (document.selection &amp;&amp; document.selection.createRange) { // Not sure what to do here range = document.selection.createRange(); var newA = "&lt;a name='" + nameValue.replace(/'/g, "") + "'&gt;" + range.text + "&lt;/a&gt;"; range.text = newA; } } </code></pre> <p>Notice how I store the original current selection, then replace it with an <code>&lt;a&gt;</code> element that gets its <code>name</code> set with the passed-in value.</p> <p>As for the <code>document.selection</code> part (which seems to be used by IE &lt; 9), I'm not 100% sure that the code I provided will work (actually allow HTML in the selection, and not escaping it). But it's my attempt :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload