How do you match a caret (^) symbol in regex?
Escape it with a backslash: /\^/ This will make it be interpreted as a literal ^ character.
Escape it with a backslash: /\^/ This will make it be interpreted as a literal ^ character.
You could use my Rangy library, which attempts with some success to normalize browser range and selection implementations. If you’ve managed to insert the <a> as you say and you’ve got it in a variable called aElement, you can do the following: var range = rangy.createRange(); range.setStartAfter(aElement); range.collapse(true); var sel = rangy.getSelection(); sel.removeAllRanges(); sel.addRange(range);
Maybe I’m misreading the question, but wouldn’t the following do (assuming an editable <div> with id “editable”)? The timer is there because in Chrome, the native browser behaviour that selects the whole element seems to trigger after the focus event, thereby overriding the effect of the selection code unless postponed until after the focus event: … Read more
These are the list of Native Caret functions provided by Windows you can use them for you application. [DllImport(“User32.dll”)] static extern bool CreateCaret(IntPtr hWnd, int hBitmap, int nWidth, int nHeight); [DllImport(“User32.dll”)] static extern bool SetCaretPos(int x, int y); [DllImport(“User32.dll”)] static extern bool DestroyCaret(); [DllImport(“User32.dll”)] static extern bool ShowCaret(IntPtr hWnd); [DllImport(“User32.dll”)] static extern bool HideCaret(IntPtr hWnd); … Read more
Firstly, think about why you’re doing this. If you’re trying to stop users from editing certain elements, just set contenteditable to false on those elements. However, it is possible to do what you ask. The code below works in Safari 4 and will return the node the selection is anchored in (i.e. where the user … Read more
The following function will work in all major browsers, for both textareas and text inputs: function moveCaretToEnd(el) { if (typeof el.selectionStart == “number”) { el.selectionStart = el.selectionEnd = el.value.length; } else if (typeof el.createTextRange != “undefined”) { el.focus(); var range = el.createTextRange(); range.collapse(false); range.select(); } } However, you really shouldn’t do this whenever the user … Read more
You can set the caret position using CaretIndex property of a TextBox. Please bear in mind that this is not a DependencyProperty. Nevertheless, you may still set it in XAML like this: <TextBox Text=”123″ CaretIndex=”{x:Static System:Int32.MaxValue}” /> Please remember to set CaretIndex after Text property or else it will not work. Thus it probably won’t … Read more
This is a VERY basic example. This basically walks the document to find the position of the word within the document and ensures that the text is moved to the viewable area. It also highlights the match public class MoveToText { public static void main(String[] args) { new MoveToText(); } public MoveToText() { EventQueue.invokeLater(new Runnable() … Read more
These are blocks which add anonymous functions and function objects to Objective-C. See e.g. Introducing Blocks and Grand Central Dispatch : Block objects (informally, “blocks”) are an extension to C, as well as Objective-C and C++, that make it easy for programmers to define self-contained units of work. Blocks are similar to — but far … Read more
// Get the focused element: var $focused = $(‘:focus’); // No jQuery: var focused = document.activeElement; // Does the element have focus: var hasFocus = $(‘foo’).is(‘:focus’); // No jQuery: elem === elem.ownerDocument.activeElement; Which one should you use? quoting the jQuery docs: As with other pseudo-class selectors (those that begin with a “:”), it is recommended … Read more