Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This will work. (note: with quotes it's at 8 else at 7)</p> <pre><code>$("#tf").on('keyup', function(){ console.log($(this).val().indexOf('*')); });​ </code></pre> <p><a href="http://jsfiddle.net/Vandeplas/hc6ZH/" rel="nofollow">http://jsfiddle.net/Vandeplas/hc6ZH/</a></p> <p><strong>UPDATE:</strong> solution with multiple *</p> <pre><code>$("#tf").on('keyup', function(){ var pos = [], lastOc = 0, p = $(this).val().indexOf('*',lastOc); while( p !== -1){ pos.push(p); lastOc = p +1; p = $(this).val().indexOf('*',lastOc); } console.log(pos); });​ </code></pre> <p><a href="http://jsfiddle.net/Vandeplas/hc6ZH/1/" rel="nofollow">http://jsfiddle.net/Vandeplas/hc6ZH/1/</a></p> <p><em><strong>UPDATE:</em></strong> giving only the position of the * char you just typed</p> <pre><code>(function ($, undefined) { $.fn.getCursorPosition = function() { var el = $(this).get(0); var pos = 0; if('selectionStart' in el) { pos = el.selectionStart; } else if('selection' in document) { el.focus(); var Sel = document.selection.createRange(); var SelLength = document.selection.createRange().text.length; Sel.moveStart('character', -el.value.length); pos = Sel.text.length - SelLength; } return pos; } })(jQuery); $("#tf").on('keypress', function(e){ var key = String.fromCharCode(e.which); if(key === '*') { var position = $(this).getCursorPosition(); console.log(position); } else { return false; } });​ </code></pre> <p><a href="http://jsfiddle.net/Vandeplas/esDTj/1/" rel="nofollow">http://jsfiddle.net/Vandeplas/esDTj/1/</a></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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